Skip to content

generic function parameter infers boolean as true #29400

Open
@aleclarson

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Domain: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions