Skip to content

Unexpected Error for conditional type parameter if value is generic typed #50066

Closed

Description

@DerZyklop

Bug Report

🔎 Search Terms

generic
conditional type
error

🕗 Version & Regression Information

Happens in every version available in TS Playground, including Nightly.

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics and conditional type
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

const doSomething : <T>(
  input : (T extends undefined ? never : T) | null
) => void = (input) => {
  console.log(input);
}


/* The unexpected Error */
const functionWithGenericType = <T extends string | null>(input : T) => {
  doSomething(input); // Error: Type 'string' is not assignable to type 'T extends undefined ? never : T'.
}

/* Just some test to proove that the rest of my code is working as expected… */
const greeting : string | null = Math.random() > 0.5 ? 'Hello' : null;
doSomething(greeting); // No Error. As expected.

🙁 Actual behavior

An error appears when calling doSomething(input) from inside a function with generic typed input.

🙂 Expected behavior

No Error appears.

Activity

  1. MartinJohns commented on Jul 27, 2022

    @MartinJohns
    Contributor

    Resolving of conditional types involving unbound generic type arguments is deferred. At that point the compiler doesn't know what T extends undefined ? never : T resolves to, because the compiler doesn't know what type T is. Constraints are not taken into consideration. Same as #48243.

    When actually calling the function the type argument is not unbound anymore, so the conditional type can be resolved.

  2. typescript-bot commented on Jul 30, 2022

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  3. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions