You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Getting lots of issues with a template string inference pattern I use in GitLens for creating strongly typed versions of string-based settings. And in TS 4.5-beta (and the currently nightly) I am getting Argument of type '* is not assignable to parameter of type errors with that pattern
🔎 Search Terms
🕗 Version & Regression Information
This is a crash
This changed between versions 4.4.4 and 4.5-beta and still present in 4.5.0-dev.202111101
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 _______
typeSubPath<T,KeyextendskeyofT>=Keyextendsstring
? T[Key]extendsRecord<string,any>
?
| `${Key}.${SubPath<T[Key],Exclude<keyofT[Key],keyofany[]>>&string}`
| `${Key}.${Exclude<keyofT[Key],keyofany[]>&string}`
: never
: never;typePath<T>=SubPath<T,keyofT>|keyofTextendsstring|keyofT ? SubPath<T,keyofT>|keyofT : keyofT;typePathValue<T,PextendsPath<T>>=Pextends `${infer Key}.${infer Rest}`
? KeyextendskeyofT
? RestextendsPath<T[Key]>
? PathValue<T[Key],Rest>
: never
: never
: PextendskeyofT
? T[P]
: never;exportinterfaceConfig{foo: {bar: {baz: boolean;};};}typeConfigPath=Path<Config>;typeConfigPathValue<PextendsConfigPath>=PathValue<Config,P>;exportclassConfiguration{get(): Config;get<TextendsConfigPath>(section: T,defaultValue?: ConfigPathValue<T>,): ConfigPathValue<T>;get<TextendsConfigPath>(section?: T,defaultValue?: ConfigPathValue<T>,): Config|ConfigPathValue<T>{returnundefinedasany;}}constconfiguration=newConfiguration();constvalue=configuration.get('foo.bar.baz');// <-- Argument of type '"foo.bar.baz"' is not assignable to parameter of type '"foo"' in TS 4.5-beta
Output
exportclassConfiguration{get(section,defaultValue){returnundefined;}}constconfiguration=newConfiguration();constvalue=configuration.get('foo.bar.baz');// <-- Argument of type '"foo.bar.baz"' is not assignable to parameter of type '"foo"' in TS 4.5-beta
To me, it looks like keyof T can be factored out of each side of the union, so you’re left with asking if SubPath<T, keyof T> is assignable to string. Every possible instantiation of SubPath is assignable to string, so I’m missing what this condition is supposed to be checking for.
Bizarrely, a workaround that would seem not to change the semantics of these types at all is to extract SubPath<T, keyof T> | keyof T to its own type alias. That definitely seems like a bug, but it’s hard for me to figure out how bad of a break this is because I can’t figure out the reason for the type at all. It seems to me like you could just as well define
This appears to be another manifestation of #46624. The issue disappears from the main branch after this commit, so it should also be fixed in the release-4.5 branch after the cherry pick.
@andrewbranch I think I thought I needed that extra complexity on SubPath to allow for deeper nesting, but it looks like type Path<T> = SubPath<T, keyof T> | keyof T; as you suggested works just fine. Thanks!
eamodio
added a commit
to gitkraken/vscode-gitlens
that referenced
this issue
Nov 3, 2021
Bug Report
Getting lots of issues with a template string inference pattern I use in GitLens for creating strongly typed versions of string-based settings. And in TS 4.5-beta (and the currently nightly) I am getting
Argument of type '* is not assignable to parameter of type
errors with that pattern🔎 Search Terms
🕗 Version & Regression Information
4.4.4
and4.5-beta
and still present in4.5.0-dev.202111101
⏯ Playground Link
Playground link with relevant code
💻 Code
Output
Compiler Options
🙁 Actual behavior
Argument of type '"foo.bar.baz"' is not assignable to parameter of type
🙂 Expected behavior
No errors like in TS 4.4.4 and prior
The text was updated successfully, but these errors were encountered: