2018-12-21 Typescript 爬坑

# 定义接口
interface MyInterface {
    dict: {
        [key: string]:string
    }
}
# 定义参数
function foo(o: MyInterface) {
    console.log(o.dict) 
    #不需要判断o是否有dict,能传进来肯定是有的
}
# 规定对象结构
let o:MyInterface = {
    dict: {
        'a': '2'
    }
}
foo(o) #运行

你可能感兴趣的:(2018-12-21 Typescript 爬坑)