Do you want to request a feature or report a bug? feature
What is the current behavior?
Using isLoaded helper with argument of type T | undefined doesn't narrow the type of the argument to T.
function renderTodos(todos: string[]) {
// ...
}
function Todos({ todos }: { todos: string[] | undefined }) {
// const todos: string[] | undefined
if (!isLoaded(todos)) {
return <span>Loading...</span>
}
// type error here - todos is still string[] | undefined
return <todos>{renderTodos(todos)}</todos>
}
What is the expected behavior?isLoaded function should return a type predicate so that invoking it with argument of type T | undefined narrows it down to T
function renderTodos(todos: string[]) {
// ...
}
function Todos({ todos }: { todos: string[] | undefined }) {
// const todos: string[] | undefined
if (!isLoaded(todos)) {
return <span>Loading...</span>
}
// const todos: string[]
return <todos>{renderTodos(todos)}</todos>
}
Do you want to request a feature or report a bug? feature
What is the current behavior? Using
isLoaded
helper with argument of typeT | undefined
doesn't narrow the type of the argument toT
.What is the expected behavior?
isLoaded
function should return a type predicate so that invoking it with argument of typeT | undefined
narrows it down toT