microsoft / microsoft/TypeScript
Inherited interface functions cause compile error when interface extensions are reordered.
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.8.3
Search Terms:
- Order sensitive Interface Extension
- TS2551
I have two interfaces, one providing the function toJSON(), the other toJSONLD(). I then make an interface that inherits from both of these. Depending on the order in which I place these interfaces, toJSON() and toJSONLD() get detected by intellisense and recognized by the type system, yet are marked as not found by the compiler. Additionally, minor changes to the code (like changing the generic parameter of toJSON) also cause the function to once again be detected properly.
This playground snippet has two interfaces: ThingEventBroken and ThingEventFixed. They are identical, and only differ in the order in which I specified the inheriting interfaces.
ThingEventBroken throws compile errors when trying to use the two functions, while ThingEventFixed handles them properly.
Additionally, ThingEventLobotomized uses the same interface order as ThingEventBroken, but uses any for the generic parameter to JSONAble. The issue goes away in this case.
Code
Expected behavior:
Functions provided by interface extension should be present regardless of order.
Actual behavior:
Changing the order of the interfaces results in toJSON() and toJSONLD() not being recognized by the compiler, while still being recognized by the type system.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the linked Playground snippet with TypeScript 3.8.3 and compare the broken and fixed interface-extension orders. Trace the compiler's handling of inherited interface members and generic signatures. Done means both functions compile regardless of extension order, with a regression test covering the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100