Can you declare a object literal type that allows unknown properties in typescript?

前端 未结 4 1539
[愿得一人]
[愿得一人] 2020-12-20 12:16

Essentially I want to ensure that an object argument contains all of the required properties, but can contain any other properties it wants. For example:

fu         


        
4条回答
  •  -上瘾入骨i
    2020-12-20 13:02

    Well, i hate answering my own questions, but the other answers inspired a little thought... This works:

    function foo(bar: T): void {
        console.log(bar.baz);
    }
    
    foo({baz: 1, other: 2});
    

提交回复
热议问题