Closed as not planned
Closed as not planned
Description
Bug Report
🔎 Search Terms
- remove a type from generic union as return type
- remove a type from generic union
- remove a certain type from generic
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about <Can't find anything related>
⏯ Playground Link
💻 Code
function numberToString<T>(value: T): Exclude<T, number> {
return typeof value === 'number' ? `${value}` : value;
// ^^^^^^ Error
}
// usage
function selectText(text: string | RegExp) {
// todo
}
function anotherFn(arg: number | string | RegExp) {
// this is actually working, but somehow Line 2 is still raising the error
return selectText(numberToString(arg));
}
🙁 Actual behavior
Type 'string | T' is not assignable to type 'Exclude<T, number>'.
Type 'string' is not assignable to type 'Exclude<T, number>'
🙂 Expected behavior
There should be no issue, since T is extending any
by default, hence string should absolutely be included in Exclude<T, number>
, where it should be any
type but without number
Metadata
Metadata
Assignees
Labels
No labels