-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingExperience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
TypeScript Version: master
Search Terms: generic constrained type parameter error
Code
People are regularly confused why code like this doesn't work:
function fn1<T extends string>(x: T): T {
return "hello world!";
}
function fn2<T extends HTMLElement>(obj: T): T[] {
return [obj, new HTMLDialogElement()];
}
function fn3<T extends boolean>(obj: T = false) {
}
Actual behavior: Unelaborated error like "Can't assign false
to T
"
Expected behavior:
If the source type is assignable to the constraint of a type parameter, we should issue a more specific error that attempts to explain the situation:
🚲 🏠
Type "false" is not assignable to type "T" "false" is assignable to the constraint type "boolean", but "T" could be a different more-specific type during a call
Playground Link: Link
JoshuaKGoldberg, DanielRosenwasser, cpplearner, styfle, a-tarasyuk and 23 more
Metadata
Metadata
Assignees
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingExperience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript