microsoft / microsoft/TypeScript
Discrepancy when typeToString when enclosingDeclaration is undefined vs defined.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
I'm using typeToString functionality from the typescript compiler (via ts-morph) to build auto-generated API documentation. I've run into an issue with certain types that use default generic types. My goals:
- I don't want the default parameters to show up
- I want the module/sourcefile import included
If I pass enclosingDeclaration, the default parameters don't show up, but the import is gone. If I don't pass enclosingDeclaration the opposite happens - import is there, but the default parameters show up.
🔎 Search Terms
Typescript typeToString generic optional default parameter ignore enclosingDeclaration
🕗 Version & Regression Information
I'm not sure this is bug but there is nothing I could find about it anywhere else.
⏯ Playground Link
Code sandbox which shows the issue.
💻 Code
Types:
export interface WithDefaultGenerics<A = string, B = number> {
irrelevant: string;
}
export type Test = () => WithDefaultGenerics;
const text = compiler.typeToString(
compilerType, // This is the type of `Test`
undefined,
TypeFormatFlags.UseFullyQualifiedType | TypeFormatFlags.InTypeAlias
);
console.log('text is ', text);
const text2 = compiler.typeToString(
compilerType, // This is the type of `Test`
node.compilerNode, // This is the node container of `Test`
TypeFormatFlags.UseFullyQualifiedType | TypeFormatFlags.InTypeAlias
);
console.log('text2 is ', text2);
🙁 Actual behavior
text is () => import("/Users/path/to/file").WithDefaultGenerics<string, number>
text2 is () => WithDefaultGenerics
🙂 Expected behavior
I'm trying to get () => import("/Users/path/to/file").WithDefaultGenerics
The reason this is important to me is because in conjunction with, I suspect, this issue, getting a type for (props: AllCasesProps) => ReactElement<AllCasesProps> ends up looking like this:
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
Beginne mit dem Playground-Link und den compiler typeToString-Aufrufen im Bericht und vergleiche die Ausgabe, wenn enclosingDeclaration nicht definiert ist, mit der Ausgabe, wenn es node.compilerNode ist. Untersuche, wie TypeFormatFlags.UseFullyQualifiedType und InTypeAlias die standardmäßigen generischen Argumente und modulqualifizierten Namen beeinflussen. Als erledigt gilt die Erzeugung des angeforderten qualifizierten Typs ohne Anzeige von Standardparametern, mit Regressionstests für beide Fälle.
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
- 35/100