typescript可选类型,默认类型

function test(a: string ,b?: string ,c: string = "default") {
    console.log(a);
    console.log(b);
    console.log(c);
}
test("mike")

可以看到 ?代表可选属性  =赋值代表默认属性  默认属性和可选属性 调用的时候都不需要赋值
运行结果如下

猜你喜欢

转载自blog.csdn.net/lee727n/article/details/107407593