vevlins

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

  •  
  •   vevlins · Feb 3, 2021 · 2805 views
    This topic created in 1950 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
        1
    rexchen94  
       Feb 3, 2021
    const { p,pp } : {p:Person,pp:number} = {
    p: {name: "pony"},
    pp: 1111111,
    };
    LongMaoz
        2
    LongMaoz  
       Feb 3, 2021
    楼上正解
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6120 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 02:55 · PVG 10:55 · LAX 19:55 · JFK 22:55
    ♥ Do have faith in what you're doing.