-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editorThe issue relates to showing completion lists in an editorHelp WantedYou can do thisYou can do this
Milestone
Description
Bug Report
Optional properties in inferred mapped type causes auto-completion to break.
π Search Terms
Inferred mapped type with optional properties no auto-complete
π Version & Regression Information
I believe it never worked.
β― Playground Link
π» Code
type A1<T extends object> = {
[K in (keyof T | 'autoCompleteProp')]:
K extends 'autoCompleteProp'
? boolean
: K extends keyof T
? T[K] extends object
? A1<T[K]>
: object
: never;
}
type A2<T extends object> = {
[K in (keyof T | 'autoCompleteProp')]?: // <---- this is the only difference compared to A1
K extends 'autoCompleteProp'
? boolean
: K extends keyof T
? T[K] extends object
? A2<T[K]>
: object
: never;
}
function makeA1<T extends A1<T>>(t: T) {
return t;
}
function makeA2<T extends A2<T>>(t: T) {
return t;
}
makeA1({
autoCompleteProp: true, // <-- you CAN autoComplete 'autoCompleteProp' here
bla: {
autoCompleteProp: true, // <-- you CAN autoComplete 'autoCompleteProp' here
blubb: {
autoCompleteProp: false, // <-- you CAN autoComplete 'autoCompleteProp' here
bleh: {
// <-- you CAN autoComplete 'autoCompleteProp' here
}
},
},
});
makeA2({
autoCompleteProp: true, // <-- you CAN autoComplete 'autoCompleteProp' here
bla: {
// <-- you CAN'T autoComplete 'autoCompleteProp' here
blubb: {
// <-- you CAN'T autoComplete 'autoCompleteProp' here
bleh: {
// <-- you CAN'T autoComplete 'autoCompleteProp' here
},
},
},
});
π Actual behavior
No auto-completion offered by editor or IDE in marked lines when pressing CTRL + SPACE
or a
Edit: You can enter autoCompleteProp: '',
in the lines where auto-completion fails. The compiler will complain that autoCompleteProp
must be a boolean
. Thus, the information about the optional property is there, it's just that it never appears in the auto-completion results.
π Expected behavior
Auto-complete suggestion for "autoCompleteProp" in every line marked with <--
sadeghbarati, zardoy, ifeltsweet, xylophonehero, mrmntte and 1 moresadeghbarati, mrmntte and victorgarciaesgi
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editorThe issue relates to showing completion lists in an editorHelp WantedYou can do thisYou can do this