generic function parameter infers boolean as true #29400
Open
Description
opened on Jan 14, 2019
TypeScript Version: 3.3.0-dev.201xxxxx
Search Terms: true boolean generic function extends default
Code
const fn = <T extends boolean>(flag: T | false = false) => flag
fn({} as boolean)
// The only workaround?
fn<boolean>({} as boolean)
Expected behavior:
Expected fn<boolean>(flag?: boolean)
to be inferred
Actual behavior:
Instead got fn<true>(flag?: boolean)
as the inferred type.
The issue stems from T | false
, which is required for = false
to work.
Playground Link: Click here
Related Issues: Possibly #28154
Activity