此语法
<input
type="file"
id="input"
onChange={let a = 1; e => this.setFilePath(e.target.files[0])}
/>生成警告
Object is possibly 'null'.如何在不求助于// @ts-ignore:的情况下处理此问题?
发布于 2019-07-23 23:52:31
诚然,// @ts-ignore并不比//@ts-ignore更优雅,但是如果e.target.files[0]永远不会为null,您可以使用not-null assertion operator (感叹号)。
<input
type="file"
id="input"
onChange={let a = 1; e => this.setFilePath(e.target.files[0]!)}
/>https://stackoverflow.com/questions/57167387
复制相似问题