- Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
Description
π Search Terms
5.4 regression
π Version & Regression Information
- This changed between versions 5.3.3 and 5.4-beta
β― Playground Link
π» Code
export type ExtractRouteParams<T extends string> = string extends T ? Record<string, string> : T extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [k in Param | keyof ExtractRouteParams<Rest>]: string } : T extends `${infer _Start}:${infer Param}` ? { [k in Param]: string } : {}; declare function link<T extends string>( args: { path: T; } & ({} extends ExtractRouteParams<T> ? { params?: {} } : { params: ExtractRouteParams<T> }), ): void; // error in ts 5.3.3 and 5.4.0-beta link({ path: '/:foo/:bar', params: {} }); // error in ts 5.3.3, no error in ts 5.4.0-beta link({ path: '/:foo/:bar/', params: { foo: 'foo' } });
π Actual behavior
The last line is only an error in TS 5.3.3, not TS 5.4-beta.
π Expected behavior
I'd expect it to be an error in both (foo
isn't specified).
Additional information about the issue
Putting NoInfer
in the conditional type makes the expected error reappear:
- } & ({} extends ExtractRouteParams<T> ? { params?: {} } : { params: ExtractRouteParams<T> }), + } & ({} extends ExtractRouteParams<NoInfer<T>> ? { params?: {} } : { params: ExtractRouteParams<NoInfer<T>> }),
So perhaps this is WAI? Just wanted to flag it as a change I noticed from 5.3.3 to 5.4-beta.
Metadata
Metadata
Assignees
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options