-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
π Search Terms
.find
narrow find
π Version & Regression Information
5.0.2
β― Playground Link
Playground link with relevant code
π» Code
type Foo = {
discriminator: 'bar',
value: number
} | {
discriminator: 'baz',
value: string
}
function assertString (param: string) {}
function assertNumber (param: number) {}
function func (param: Foo[]) {
const found = param.find((p) => p.discriminator === 'bar')
if (!found) return
assertNumber(found.value) // < issue
if (found.discriminator === 'bar') assertNumber(found.value) // < no problem
}
π Actual behavior
The find does not narrow the returned type
π Expected behavior
The logical flow SHOULD narrow it. Typescript IS capable of this. I understand the check is in another scope, but can't it be propagated upwards?
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created