这类似于#40796374 https://stackoverflow.com/questions/40796374/property-x-does-not-exist-on-type-never但这是关于类型的,而我正在使用接口。
给出下面的代码:
interface Foo {
name: string;
}
function go() {
let instance: Foo | null = null;
let mutator = () => {
instance = {
name: 'string'
};
};
mutator();
if (instance == null) {
console.log('Instance is null or undefined');
} else {
console.log(instance.name);
}
}
我收到错误消息“属性‘名称’在‘从不’类型上不存在”。
我不明白实例怎么可能是“从不”。有人能解释一下吗?
如果将组件写为React.FC
,并使用useState()
,你可以这样写:
const [arr, setArr] = useState<any[]>([])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)