microsoft / microsoft/TypeScript

Inherited interface functions cause compile error when interface extensions are reordered.

Open
#38,185 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Investigation
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

Playground snippet

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.