7.0 regression: inherited members are sorted by position, so an empty subinterface changes assignability

Ouverte
#65,052 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@timurzvural y travaille déjà.

Depuis le 30/10/2026.

  • #65065 par @timurzvural — ouverte
  • #65093 par @ahejlsberg — ouverte

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
25/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
typescript
Domaine
compilers

Piste de recherche

Start by reviewing getNamedMembers in 7.0.2 or createMemberLayout on main, then compare how inherited members are ordered in the reproduction's deep.ts. Run tsc --noEmit --pretty false deep.ts and check whether wideC produces the same assignability error as wideB; an open linked pull request indicates work is already underway.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

🔎 Search Terms

inherited members order, member order, property order, interface extends, empty subinterface, variance, unmeasurable, getNamedMembers, createMemberLayout, missing TS2322, 7.0 regression

🕗 Version & Regression Information
  • This changed between versions 6.0.3 and 7.0.2
  • Still present in 7.1.0-dev.20261030.1.
  • microsoft/typescript-go#1987 (first in @typescript/native-preview 7.0.0-dev.20251031.1) fixed this for one level of inheritance (B below), but not for two (C).
⏯ Playground Link

No response

(Reproduction repo can be found here - it doesn't seem like Playground runs an applicable version for this issue).

💻 Code
export const empty: C<string> = {};
declare const narrowB: B<{ a: string }>;
export const wideB: B<{ a: string; b?: number }> = narrowB;
declare const narrowC: C<{ a: string }>;
export const wideC: C<{ a: string; b?: number }> = narrowC;

interface A<T> {
  inherited: () => T;
}
interface B<T> extends A<T> {
  own: (x: T) => Required<T>;
}
interface C<T> extends B<T> {}

Run with tsc --noEmit --pretty false deep.ts and no tsconfig, since strict is the default. empty is only there for its message, which lists C's members in the order the checker compares them.

🙁 Actual behavior

With 7.0.2 and 7.1.0-dev.20261030.1, wideC compiles, though C adds nothing to B and the same assignment to B is an error:

deep.ts(1,14): error TS2739: Type '{}' is missing the following properties from type 'C<string>': inherited, own
deep.ts(3,14): error TS2322: Type 'B<{ a: string; }>' is not assignable to type 'B<{ a: string; b?: number | undefined; }>'.
  The types returned by 'own(...)' are incompatible between these types.
    Property 'b' is missing in type 'Required<{ a: string; }>' but required in type 'Required<{ a: string; b?: number | undefined; }>'.
🙂 Expected behavior

wideC is an error, like wideB, as in 6.0.3:

deep.ts(1,14): error TS2739: Type '{}' is missing the following properties from type 'C<string>': own, inherited
deep.ts(3,14): error TS2322: Type 'B<{ a: string; }>' is not assignable to type 'B<{ a: string; b?: number | undefined; }>'.
  The types returned by 'own(...)' are incompatible between these types.
    Property 'b' is missing in type 'Required<{ a: string; }>' but required in type 'Required<{ a: string; b?: number | undefined; }>'.
deep.ts(5,14): error TS2322: Type 'C<{ a: string; }>' is not assignable to type 'C<{ a: string; b?: number | undefined; }>'.
  The types returned by 'own(...)' are incompatible between these types.
    Property 'b' is missing in type 'Required<{ a: string; }>' but required in type 'Required<{ a: string; b?: number | undefined; }>'.
Additional information about the issue

C has no members of its own, so all of its properties are inherited, and they are sorted by declaration position (getNamedMembers in 7.0.2, createMemberLayout on main): inherited, declared in A, comes before own, declared in B. 6.0 takes C's inherited members from B in B's order, which puts B's own members first: own, inherited.

The order changes assignability through variance measurement, which relates C<Sub> to C<Super> and back member by member, stopping at the first member that fails. Required<T> in own marks T unmeasurable (the -?), but only when relating C<Super> to C<Sub>, and that direction fails at inherited first when inherited comes first. T is then measured plain invariant: --generateTrace shows B as [in out (unmeasurable)] and C as [in out]. Invariant, wideC passes because { a: string } and { a: string; b?: number } are each assignable to the other, while wideB gets the structural check that finds own's return types incompatible.

A fix: order inherited members by base type, and within a base type in that base's order, as 6.0 does.

Related, and already fixed on main: in 7.0.2 the order could also depend on other files. An inherited member counted as the interface's own when its text range fell inside the range of one of the interface's declarations in another file, such as a module augmentation, because isDeclarationContainedBy doesn't compare files, so a longer comment in an augmentation could make an assignment compile. #64915 replaced that check for classes and interfaces (first in 7.1.0-dev.20261024.1). I can share a repro if it matters for 7.0.

Found because a library relies on a -? member like own for exact assignments between instantiations of its schema type, and interfaces extending that type lost them on 7.0.

Langage dominant
Go
Étoiles
112k
Forks
15.4k
Merge moyen
2 j 21 h
PR mergées (30 j)
126

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de microsoft/TypeScript

Toutes les issues de microsoft/TypeScript

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.