Home
Sign Up
Sign In
V2EX
›
问与答
如何使 const age = 18 的 typescript 类型推断是 数字 18 而不是 number
TomVista
·
Jul 13, 2021
· 1432 views
This topic created in 1790 days ago, the information mentioned may be changed or developed.
TypeScript
const
age
number
4 replies
1
llej
Jul 13, 2021
const age = 18 as const
2
TomVista
OP
Jul 13, 2021
@
llej
我之前用的差不多的形式
const age = 18 as 18
实在懒得写 as
3
hyrious
Jul 13, 2021
https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhgcwKYwLwwCwCYBQfFI5A
我看现在默认就是推断成 18 呀
4
TomVista
OP
Jul 13, 2021
@
hyrious
我的 vscode 不认..
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Solana
·
6142 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 30ms ·
UTC 02:54
·
PVG 10:54
·
LAX 19:54
·
JFK 22:54
♥ Do have faith in what you're doing.
❯