我需要在Chrome中覆盖一个实验属性,并遇到此错误。
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual'; // type error
}
我在以下位置找到了答案: http :
(history as any).scrollRestoration = 'manual';
与
history['scrollRestoration'] = 'manual';
看来TypeScript的docs /深入研究书没有提到方括号语法。
最有用的评论
我会去第一个。 第二个有效,但仅当您不使用
-noImplicitAny
编译时。