Multiple type signatures for members, Union Types in TypeScript

前端 未结 3 1338
失恋的感觉
失恋的感觉 2020-12-29 19:25

If I have a property that might be a string or a boolean how do I define it:

interface Foo{
    bar:string;
    bar:boolean;
}

I don\'t want

3条回答
  •  情话喂你
    2020-12-29 19:50

    This is usually referred to as "union types". The TypeScript type system from 1.4 does allow for this.

    See: Advanced Types

提交回复
热议问题