关于前端:TS-interface-type-class-中的分号逗号

6次阅读

共计 375 个字符,预计需要花费 1 分钟才能阅读完成。

// ↓ 接口 interface
interface Interface1 {
    name:string; // ← 分号
    age:number, // ← 逗号
    sex?:string // ← 不写分号,也不写逗号
    interests?:string[];}
// ↓ 类型 type
type Type1 = {
    name:string;
    age:number,
    sex?:string
    interests?:string[];}
const in1:Interface1 = {name:'张三', age:18}
console.log(in1.name);

const t1:Type1 = {name:'李四', age:13}
console.log(t1.age);

下面对于 interface, type 的写法都没有语法错误(不会报错)

论断:
interface 和 type 中能够用分号或逗号,
留神:class 中只能用分号。

正文完
 0