microsoft / microsoft/TypeScript
Non-exported classes in type declaration files leaking value names
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
TypeScript Version: 3.5.2
Search Terms: ambient module declaration export declare class type name
Code
In a file called classes.d.ts:
declare class A {}
export declare class B extends A {}
In a file called test.js:
let a = require('classes').A;
In a file called test.ts:
import { A } from './types/classes';
[NEW] Assumptions:
The following is a list of assumptions I had when originally opening this issue:
- Type Declaration Files work like modules: once you use
importorexport[on a top-level declaration], only explicitlyexported declarations are visible externally. - Type names declared in a Declaration File are always accessible via
importtypes (at least those that are used byexported types.- E.g.
export class B extends Aexports the type namesAandB, even ifAwas not directlyexported.
- E.g.
- Value names declared in a module-style Declaration File (see
#1above) are only accessible if explicitlyexported.
These assumptions are the result of reading the documentation and working with declaration files. Note that the documentation does not mention:
- All declarations in a declaration file are implicitly exported.
- Special [and undocumented?]
export {};syntax causes only explicitlyexported declarations to be available by consumers of the declaration file.
I list them here to provide context for the Expected Behavior section.
Expected behavior:
In both cases , an Error that name 'A' could be found in module 'classes'.
I expect in this case that TypeScript is capable of resolving the following from the declaration file:
In other words, I should be able to use import types to resolve class A, but attempts to use them should fail.
Actual behavior:
No compiler error in either case. TypeScript-powered IDEs (e.g. VSCode) happily show that the full non-exported class A is available.
In short, a non-exported, declared class should resolve in the same way as an interface.
As things stand today, TypeScript erroneously resolves the Value "A".
Playground Link: NA
Related Issues: NA
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Verhalten anhand der classes.d.ts-, test.js- und test.ts-Beispiele im Issue und verfolge anschließend die Modul- und Symbolauflösung von Deklarationsdateien im TypeScript compiler. Erledigt ist die Aufgabe, wenn die nicht exportierte Klasse A nicht als Wert offengelegt wird, während die für die exportierte Klasse B erforderlichen Typreferenzen weiterhin aufgelöst werden, mit Regressionstests für beide Beispiele.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100