Skip to content

Generics Extending Distributed Conditionals Cannot be Narrowed #45174

@anthonyjoeseph

Description

@anthonyjoeseph

Bug Report

🔎 Search Terms

Generics, Union, Narrow, Narrowing, Distributed, Conditional, Inference

🕗 Version & Regression Information

TS v4.3.5 (and nightly build as of 7/23/2021)

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about conditional types & inference

⏯ Playground Link

Playground link with relevant code

💻 Code

type Tuplify<A> = A extends unknown ? [A] : never
type test = Tuplify<'a' | 'b'> // test = ['a'] | ['b']

declare const inferFunc: <A, R extends Tuplify<A>>(a: A, b: R) => R
declare const testval: 'a' | 'b'
const retval: ['a'] = inferFunc(testval, ['a']) // this should work (?)

🙁 Actual behavior

const retval: ['a'] | ['b']

🙂 Expected behavior

const retval: ['a']

I expected R to be inferred as a subtype of Tuplify<A>, since that's how parameterized union types work as of #13995 (I think)

Please forgive me if this is actually expected behavior or has already been reported

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions