TomVista
V2EX  ›  问与答

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

  •  
  •   TomVista · Jul 13, 2021 · 1799 views
    This topic created in 1954 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   ·   2474 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:07 · PVG 19:07 · LAX 03:07 · JFK 06:07
    ♥ Do have faith in what you're doing.