Microsoft/TypeScript

Missing property incompatible error when there is a namespace with a value export

Open

#54.131 geöffnet am 4. Mai 2023

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: Index TypesHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

Bug Report

🔎 Search Terms

index signature, namespace

🕗 Version & Regression Information

  • This is the behavior in every version I tried: v4.9.4, v5.0.4

⏯ Playground Link

Playground link with relevant code

💻 Code

interface Dict {
  [key: string]: unknown;
}

interface Thing {}
interface ThingWithNamespaceWithValueExport {}
namespace ThingWithNamespaceWithValueExport {
  export const asdasd: string = '';
}
interface ThingWithNamespaceWithTypeExport {}
namespace ThingWithNamespaceWithTypeExport {
  export type asdasd = string;
}

interface Foo {
  prop?: Dict;
}
interface Bar extends Foo {
  //             ~~~ Interface 'Bar' incorrectly extends interface 'Foo'. Types of property 'prop' are incompatible. Type 'Thing' is not assignable to type 'Dict'. Index signature for type 'string' is missing in type 'Thing'.
  prop: Thing;
}
interface Baz extends Foo {
  // No error here. But I would expect the same error.
  prop: ThingWithNamespaceWithValueExport;
}
interface Quux extends Foo {
  //             ~~~~ Interface 'Quux' incorrectly extends interface 'Foo'. Types of property 'prop' are incompatible. Type 'ThingWithNamespaceWithTypeExport' is not assignable to type 'Dict'. Index signature for type 'string' is missing in type 'ThingWithNamespaceWithTypeExport'.
  prop: ThingWithNamespaceWithTypeExport;
}

🙁 Actual behavior

No error for interface Baz, where prop is the type of an interface with a namespace, which exports a value.

🙂 Expected behavior

Same error for Baz that we get for Bar and Quux.

Contributor Guide