microsoft / microsoft/TypeScript
Discrepancy when typeToString when enclosingDeclaration is undefined vs defined.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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:
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il link Playground e le chiamate compiler typeToString nel report, confrontando l’output quando enclosingDeclaration non è definito con quello quando è node.compilerNode. Analizza in che modo TypeFormatFlags.UseFullyQualifiedType e InTypeAlias influenzano gli argomenti generici predefiniti e i nomi qualificati dal modulo. Il lavoro è completo quando viene prodotto il tipo qualificato richiesto senza mostrare i parametri predefiniti, con una copertura di regressione per entrambi i casi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100