typescript语法

typescript

1.let/const

typescript 复制代码
    let msg:string='hello'
    let age:number=11
    let isDone:boolean=true

2.数据类型

typescript 复制代码
string
number
boolean
any
void
null
undefined
never
object
array
tuple
enum

3.interface

typescript 复制代码
    interface Person{
        name:string;
        age:number;
        sex?:string;
        readonly school:string;
        greet():void;
        [prop:string]:string;
    }
    let person:Person={name:'ivan',age:30}

4.联合类型与交叉类型

typescript 复制代码
    let v:string|number=12
    type Admin=Employee&Manager

5.泛型

typescript 复制代码
    function ide<T>(arg:T):T{
        return arg
    }
    let out=ide<number>(12)

6.类型别名

typescript 复制代码
    type UserId=string
    let id:UserId='test11'

7.类型断言

typescript 复制代码
let v:any='test'
let d:number=(<string>v).length
let c:number=(v as string).length

8.装饰器

typescript 复制代码
    function log(value:any,constructor:any){
        console.log(`${constructor.name}`)
    }
    @log
    class Student{
        constructor(){
            console.log('constructor')
        }
    }
    const s=new Student()
相关推荐
东东5161 小时前
基于ssm的网上房屋中介管理系统vue
前端·javascript·vue.js
harrain2 小时前
什么!vue3.4开始,v-model不能用在prop上
前端·javascript·vue.js
阿蒙Amon7 小时前
TypeScript学习-第7章:泛型(Generic)
javascript·学习·typescript
睡美人的小仙女1277 小时前
Threejs加载环境贴图报错Bad File Format: bad initial token
开发语言·javascript·redis
fanruitian7 小时前
uniapp android开发 测试板本与发行版本
前端·javascript·uni-app
rayufo7 小时前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
RANCE_atttackkk7 小时前
[Java]实现使用邮箱找回密码的功能
java·开发语言·前端·spring boot·intellij-idea·idea
摘星编程8 小时前
React Native + OpenHarmony:Timeline垂直时间轴
javascript·react native·react.js
2501_944525549 小时前
Flutter for OpenHarmony 个人理财管理App实战 - 支出分析页面
android·开发语言·前端·javascript·flutter
jin12332210 小时前
React Native鸿蒙跨平台完成剧本杀组队详情页面,可以复用桌游、团建、赛事等各类组队详情页开发
javascript·react native·react.js·ecmascript·harmonyos