Skip to content

with infer in template string, suggestion works in 4.6, but not work in 4.7ย #49680

@xxleyi

Description

@xxleyi

Bug Report

๐Ÿ”Ž Search Terms

suggestion pathof

๐Ÿ•— Version & Regression Information

4.7

โฏ Playground Link

Playground link with relevant code

๐Ÿ’ป Code

// get from https://github.com/microsoft/TypeScript/issues/20423#issuecomment-812564842
type PathOf<T, K extends string, P extends string = ""> =
  K extends `${infer U}.${infer V}`
    ? U extends keyof T ? PathOf<T[U], V, `${P}${U}.`> : `${P}${keyof T & (string | number)}`
    : K extends keyof T ? `${P}${K}` : `${P}${keyof T & (string | number)}`;


declare function consumer<K extends string>(path: PathOf<{a: string, b: {c: string}}, K>) : number;

// suggestion works well in 4.6, and not work in 4.7
consumer('b.')

๐Ÿ™ Actual behavior

image

๐Ÿ™‚ Expected behavior

image

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions