-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ts笔记: Everyday Types #65
Milestone
Comments
类型断言ts 不允许 ‘不可能’的类型断言。比如
这种情况下的解决方法就是断言2次,先转化为any/unknown, 再断言为其他类型
|
联合类型使用type U= A|B 如果使用的是A 跟B都有的属性,那么ts不会报错,
|
Null 和 Undefined项目建议开启 strictNullChecks 如果你知道变量一定存在,则可以使用:非空断言操作符
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
字面量类型推断
数字和字符串的字面量会被推断为 number 和string类型,所以常见的报错:
的解决方法
The text was updated successfully, but these errors were encountered: