Type definition in object literal in TypeScript

后端 未结 9 2515
粉色の甜心
粉色の甜心 2020-11-27 09:29

In TypeScript classes it\'s possible to declare types for properties, for example:

class className {
  property: string;
};

How do declare

9条回答
  •  独厮守ぢ
    2020-11-27 09:53

    If you're trying to add typings to a destructured object literal, for example in arguments to a function, the syntax is:

    function foo({ bar, baz }: { bar: boolean, baz: string }) {
      // ...
    }
    
    foo({ bar: true, baz: 'lorem ipsum' });
    

提交回复
热议问题