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
{{ message }}
Repository navigation
Template literal value not assignable to template literal type #56659
typeRegistry={a: {a1: {}}b: {b1: {}}}typeKeyof<T>=keyofT&stringfunctionf1<ScopeextendsKeyof<Registry>,EventextendsKeyof<Registry[Scope]>>(eventPath: `${Scope}:${Event}`){const[scope,event]=eventPath.split(":")console.log(scope,event)}functionf2<ScopeextendsKeyof<Registry>,EventextendsKeyof<Registry[Scope]>>(scope: Scope,event: Event){// It errors here with:// Argument of type '`${Scope}:${Event}`' is not assignable to parameter of type '`${Scope}:${Keyof<Registry[`${Scope}`]>}`'.(2345)f1(`${scope}:${event}`)}
🙁 Actual behavior
When calling the function f1 with a template literal value built with the same types than the template literal type parameter, it errors with:
Argument of type '${Scope}:${Event}' is not assignable to parameter of type '${Scope}:${Keyof<Registry[${Scope}]>}'.(2345)
🙂 Expected behavior
When calling the function f1 with a template literal value built with the same types than the template literal type parameter, I would expect no error.
Additional information about the issue
The message error message has changed over time, in versions 4.1.5 and 4.2.3 it was:
Argument of type 'string' is not assignable to parameter of type 'never'. (2345)
Since version 4.3.5 it is:
Argument of type '${Scope}:${Event}' is not assignable to parameter of type '${Scope}:${Keyof<Registry[${Scope}]>}'.(2345)
Activity
RyanCavanaugh commentedon Dec 8, 2023
Seems like a problem in inference rather than assignability. The call works with explicit type args:
patrick-bricout-spendesk commentedon Dec 11, 2023
Thanks for response Ryan, this is good to know that I can use this workaround which is not too cumbersome for now.
gabritto commentedon Jan 25, 2024
An example that doesn't involve string types (and is therefore not fixed by #55371) of the same inference problem: