Home
Sign Up
Sign In
V2EX
›
问与答
如何使 const age = 18 的 typescript 类型推断是 数字 18 而不是 number
TomVista
·
Jul 13, 2021
· 1431 views
This topic created in 1789 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
·
1016 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 28ms ·
UTC 18:45
·
PVG 02:45
·
LAX 11:45
·
JFK 14:45
♥ Do have faith in what you're doing.
❯