TypeScript记录 has no initializer && is not definitely assigned in the construtor

281 阅读1分钟

通过Prop传来一个外部的数据,ts报错

Property 'value' has no initializer and is not definitely assigned in the constructor.

可外部传来的,咋可能没有初始值呢??

怎么解决?

在value后面加一个'!'就可以了

意思就是你别管我有没有初始值这个问题,我能保证传过来的是肯定有的