二、typescript变量声明

  var声明
    let声明
    const声明
    declare 声明文件
    
    declare var 声明全局变量
    declare function 声明全局函数
    declare class  声明全局类
    declare enum  声明全局枚举类型
    declare namespace  声明(含有子属性的)全局对象
    interface  type  声明全局类型
    export  导出变量
    export namespace 导出(含有子属性的)对象
    export default ES6的默认导出
    export =    commonjs导出模块
    declare global   扩展全局变量
    declare module  扩展模块
    ///   三斜线指令

declare class 语句也只能用来定义类型,不能用来定义具体的实现,比如定义 sayHi 方法的具体实现则会报错

 declare class P{
        name:string;
        constructor(name:string);
        hi(){ return 'my name is'+this.name}  //error    
    }
    
内置对象:
EcMaScript内置对象:
Boolean Error Date RegExp等
  let b:Boolean = new Boolean(1)
    
Dom和Bom内置对象:
Document、HTMLElement、 Event 、NodeList等
元祖:
数组合并了相同类型的对象,而元祖(Tuple)合并了不同类型的对象

定义一对值分别 为string和number的元祖:
let tom:[string,number] = ['str', 20]
    
    
    let tom = [string,number]
    tom[0]='sss'
    tom[1]=20
    
越界元素;

let tom:[string,number];
tom=[‘sss’,20]

tom.push(‘aaa’) //ok
tom.push(false) //error ‘true’ is not type ‘string | number’

你可能感兴趣的:(二、typescript变量声明)