with infer in template string, suggestion works in 4.6, but not work in 4.7
See original GitHub issueBug 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
🙂 Expected behavior
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
typescript - infer template string return unexpected infer result
I was thinking the following Y will return test , however, it returns never , anyone has any idea the reason why and...
Read more >Documentation - TypeScript 4.6
TypeScript now provides suggestions for when parameter names don't match between your function and its JSDoc comment. Suggestion diagnostics being shown in the ......
Read more >New Typescript features - The Software House
But first things first. When working with JavaScript files, there is a feature called Template Literals. It enables you to interpolate dynamic ...
Read more >RHSA-2021:2438 - Security Advisory - Red Hat 客户门户网站
MkdirAll are not checked for permissions (CVE-2020-15113) ... baremetal cluster] multicast traffic is not working on ovn-kubernetes ...
Read more >XSL Transformations (XSLT) Version 3.0 - W3C
It was developed by the W3C XSLT Working Group. ... The use of the term tree in this document does not imply the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m experiencing the same thing. It worked with 4.6.x, and it still works with 4.9.0-dev.20221007 and 4.8.1-rc
4.6.4
4.7.4:
It compiles fine with
"id"
as second argument with both versions, it seems to be the language server that is acting up.We have also come across a somewhat similar case where the list of suggestions in TS 4.7 (and 4.8) is no longer the same as it was in TS 4.6.
Playground link
It is worth noting that if I rewrite
pick
and makekeys
a proper array instead of a rest parameter, then the list of suggestions will include all the properties just as in TS 4.6.Another way to get around the issue is to use a slightly different definition for
pick
:It’s unfortunate that the (seemingly) more natural definition of
pick
looses its ability to provide useful suggestions. I’m curious if this is something that the TS team would consider a regression and try to revert, or is this how we should expect things to work from now on?