Working around loss of support for type constraint being self

前端 未结 3 628
野性不改
野性不改 2021-01-05 06:07

This is something I\'ve been doing in older versions of TypeScript and I use this method in C#, but it doesn\'t work in the latest 1.0 version of TypeScript.

Here\'s

3条回答
  •  走了就别回头了
    2021-01-05 06:38

    You are no longer allowed to use T here:

    class Base>
    --------------------------^
    

    You either have to make your class non-generic or use:

    class Base>
    

    The reason given for this was to make the compiler simpler:

    In our continued efforts to simplify the language, we're simplifying what generic constraints can entail.

    The added overhead in terms of type-checking, error-reporting, and design complexity did not add enough additional expressiveness to make it worthwhile for 1.0. We may revisit this in future versions of TypeScript.

    -- Breaking Changes Wiki

提交回复
热议问题