Skip to content

['a' | 'b'] expect to receive ['a'] #55225

@crazyair

Description

@crazyair

Bug Report

DeepNamePath<T> result is equal to ['a'] | ['b'], but result different

🔎 Search Terms

🕗 Version & Regression Information

  • 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 _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

export type DeepNamePath<T = any> = T extends Record<string, any>
  ? {
    [P in keyof T]: [P] | DeepNamePath<T[P]>;
  }[keyof T]
  : never;

type ddd<T = any> = ['a'] | ['b']  // result is ['a']
// type ddd<T = any> = DeepNamePath<T>;  // result is ['a'] | ['b']


function func<T = any, T1 extends ddd<T> = ddd<T>>(data: T, params: T1) {
  console.log('data', data);
  return params;
}

export const d = func({ a: '', b: '' }, ['a']);
type result = typeof d
//  ^?

🙁 Actual behavior

['a']

🙂 Expected behavior

['a' , 'b']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions