如何添加对打字稿类型系统的更多限制可以解决一些错误?
我遇到了一些问题,因为库的类型定义有错误。 解决方案是添加strictnullchecks
标志。
这对我来说真的是违反直觉的。添加限制如何消除错误?通常,这是相反的方式。
我可以找到我的错误在此github essupard earjears 。
另外,作为此用户指出:
中构建是没有意义的
严格的
项目不能在非严格的一个
,但是他们使用的是具有深通电类型的高级打字稿功能,并且没有记录他们的代码。
I had some issues building my TypeScript project because the type definitions of a library had errors.
The solution was to add the strictNullChecks
flag.
That's really counter-intuitive to me. How does adding restrictions remove errors? Usually, it's the other way around.
The error that I had can be found on this GitHub issue.
Also, as this user pointed out:
it doesn't make sense that a
strict
project cannot build in a non strict one
I tried to understand their typings, but they are using advanced TypeScript features with deep generic types and they didn't documented their code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,TypeScript实际上并未添加“检查”,它会修改
null
和Undefined
的类型,这可能会导致类型错误(实际上,这就是它的本质) ,正如我所理解的。 https://www.typescriptlang.org/tsconfig/tsconfug#strictnullang-stsconf.strictnullchecks当您打开此选项时 - 它会以一种方式导致类型错误,并且当您修复所有错误并将选项返回时 - 它将以另一种方式引起错误。
I think, typescript does not actually add "checks", it modifies types of
null
andundefined
, which may causes type errors (in fact, that's what it's meant to be), as I understood. https://www.typescriptlang.org/tsconfig#strictNullChecks ????????And when you turn this option on - it causes type errors in one way, and when you fix all errors and turn the option back - it will cause errors in another way.