TomVista
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.
    llej
        1
    llej  
       Jul 13, 2021
    const age = 18 as const
    TomVista
        2
    TomVista  
    OP
       Jul 13, 2021
    @llej

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

    实在懒得写 as
    hyrious
        3
    hyrious  
       Jul 13, 2021
    TomVista
        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.