vevlins

ts 解构中可以定义类型吗?

  •  
  •   vevlins · Feb 3, 2021 · 3124 views
    This topic created in 2120 days ago, the information mentioned may be changed or developed.

    比方:

    interface Person{
    name: string
    }
    
    const { p,pp } = {
    	p: {name: "pony"},
        pp: 1111111,
    };
    

    可以单独给 p 定义类型吗?还是只能对整个{p,pp}定义类型

    3 replies  •  2021-04-16 16:20:49 +08:00
    rexchen94
    rexchen94
    Feb 3, 2021
    1
    const { p,pp } : {p:Person,pp:number} = {
    p: {name: "pony"},
    pp: 1111111,
    };
    LongMaoz
    LongMaoz
    Feb 3, 2021
    2
    楼上正解
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2146 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:56 · PVG 22:56 · LAX 06:56 · JFK 09:56
    ♥ Do have faith in what you're doing.