TomVista
V2EX  ›  问与答

如何使 const age = 18 的 typescript 类型推断是 数字 18 而不是 number

  •  
  •   TomVista · Jul 13, 2021 · 1779 views
    This topic created in 1946 days ago, the information mentioned may be changed or developed.
    llej
    llej
    Jul 13, 2021
    1
    const age = 18 as const
    TomVista
    TomVista
    OP
    Jul 13, 2021
    2
    @llej

    我之前用的差不多的形式
    const age = 18 as 18

    实在懒得写 as
    hyrious
    hyrious
    Jul 13, 2021
    3
    TomVista
    TomVista
    OP
    Jul 13, 2021
    4
    @hyrious
    我的 vscode 不认..
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4527 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 01:21 · PVG 09:21 · LAX 17:21 · JFK 20:21
    ♥ Do have faith in what you're doing.