Constructor overload in TypeScript

前端 未结 16 2098
滥情空心
滥情空心 2020-11-28 00:42

Has anybody done constructor overloading in TypeScript. On page 64 of the language specification (v 0.8), there are statements describing constructor overloads, but there wa

16条回答
  •  忘掉有多难
    2020-11-28 01:32

    You should had in mind that...

    contructor()
    
    constructor(a:any, b:any, c:any)
    

    It's the same as new() or new("a","b","c")

    Thus

    constructor(a?:any, b?:any, c?:any)
    

    is the same above and is more flexible...

    new() or new("a") or new("a","b") or new("a","b","c")

提交回复
热议问题