Closed as not planned
Description
Bug Report
π Search Terms
- string literal type
- widen
- not assignable to
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about mapped types
β― Playground Link
Playground link with relevant code
π» Code
type StringKeyOf<T> = Exclude<keyof T, symbol>;
type JsonPointer<T> = T extends object
? { [K in StringKeyOf<T>]: `/${K}${JsonPointer<T[K]>}` | `/${K}` }[StringKeyOf<T>]
: '';
function createJsonPointer<T>(key: StringKeyOf<T>): JsonPointer<T> {
return `/${key}`;
}
π Actual behavior
Following error is emitted because StringKeyOf<T>
is falsely widened to string
:
Type '`/${string}`' is not assignable to type 'JsonPointer<T>'.
π Expected behavior
I expected the code to type check as it does if the function's type parameter is replaced with a concrete type.