vevlins

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

  •  
  •   vevlins · Feb 3, 2021 · 3091 views
    This topic created in 2103 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   ·   1842 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 87ms · UTC 06:58 · PVG 14:58 · LAX 22:58 · JFK 01:58
    ♥ Do have faith in what you're doing.