TypeScript 没有对结构体的属性初始化或者没有给对象属性初始化 未初始化的字段都是undefined


 

https://gitee.com/smallinsect/MyJS/blob/master/TypeScript/%E5%AF%B9%E8%B1%A1%E5%B1%9E%E6%80%A7%E6%9C%AA%E5%88%9D%E5%A7%8B%E5%8C%96.ts

 

interface Animal {
    name: string;
    age: number;
    egg?: number;
}

let animal: Animal = <Animal>{};
console.log('------------------------');
console.log(animal.name);
console.log('------------------------');
console.log(animal.age);
console.log('------------------------');
console.log(animal.egg);
console.log('------------------------');

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM