Skip to content

undefined is acting like any in generics extension checksΒ #49862

Closed
@ghost

Description

Bug Report

πŸ”Ž Search Terms

generic function call

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics

⏯ Playground Link

playground link

πŸ’» Code

type IfAny<T> = 0 extends (1 & T) ? true : never

declare function bool<T extends IfAny<T>>(value?: T): 'caught';
declare function bool<T>(value?: T): 'not caught';

declare function bool2<T extends {['gibberish']: T}>(value?: T): 'caught';
declare function bool2<T>(value?: T): 'not caught';

const A = bool(undefined);  // caught ???
const B = bool2(undefined); // caught ???
const C = bool();           // caught ???
const D = bool2();          // caught ???

πŸ™ Actual behavior

both implicit and explicit undefined arguments seems to act like any when used in a generic when the argument is optional. This behavior is not seen when the argument is required

πŸ™‚ Expected behavior

undefined shouldn't extend everything

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions