Typescript: 建议忽略“类型的值不存在属性”的方法

创建于 2016-01-11  ·  1评论  ·  资料来源: microsoft/TypeScript

我需要在Chrome中覆盖一个实验属性,并遇到此错误。

if ('scrollRestoration' in history) {
    history.scrollRestoration = 'manual'; // type error
}

我在以下位置找到了答案: http :

(history as any).scrollRestoration = 'manual';

history['scrollRestoration'] = 'manual';

看来TypeScript的docs /深入研究书没有提到方括号语法。

Question

最有用的评论

我会去第一个。 第二个有效,但仅当您不使用-noImplicitAny编译时。

>所有评论

我会去第一个。 第二个有效,但仅当您不使用-noImplicitAny编译时。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

kimamula picture kimamula  ·  147评论

tenry92 picture tenry92  ·  146评论

rbuckton picture rbuckton  ·  139评论

nitzantomer picture nitzantomer  ·  135评论

quantuminformation picture quantuminformation  ·  273评论