Closed as not planned
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.