-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed as not planned
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
β― Playground Link
Playground link with relevant code
π» Code
type Ref<T> = {
value: T | null;
}
function convertRef<T, U>(ref: Ref<T>, callback: (t: T) => U): Ref<U> {
if (ref.value === null) {
return ref; // error: Type 'Ref<T>' is not assignable to type 'Ref<U>'
}
return {
value: callback(ref.value),
}
}
π Actual behavior
There is an error on: Type 'Ref' is not assignable to type 'Ref'
π Expected behavior
Because of the if condition, ref value should be narrowed to { value: null }
, which should be assignable to Ref<U>
, so there shouldn't be any error.
(The ticket name might not be the best, feel free to rename if needed)
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created