Bug Report
🔎 Search Terms
union type that is too complex to represent
🕗 Version & Regression Information
TS version: 4.2.3
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about union types too complex to represent
⏯ Playground Link
Playground link with relevant code
💻 Code
I have a function that should be able to take an object along with a key name that will be present within that object with a specific type, which in this example I hardcode to string to simplify the problem:
type WithStringProperty<K extends string> = {
[P in K]: string;
};
function extractProperty<K extends string>(wrapper: WithStringProperty<K>, key: K) {
return wrapper[key];
}
This much works. But when I make my wrapper parameter a little more complex by wrapping it in DeepReadonly, it fails with the error from the title:
function extractProperty<K extends string>(wrapper: DeepReadonly<WithStringProperty<K>>, key: K) {
return wrapper[key];
}
DeepReadonly is from ts-essentials:
export declare type DeepReadonly<T> = T extends Builtin
? T
: T extends {}
? {
readonly [K in keyof T]: DeepReadonly<T[K]>;
}
: Readonly<T>;
export declare type Builtin = Primitive | Function | Date | Error | RegExp;
export declare type Primitive = string | number | boolean | bigint | symbol | undefined | null;
It doesn't seem like the combination should introduce some large combination of possible union types, but I guess I'm wrong?
🙁 Actual behavior
Error: Expression produces a union type that is too complex to represent
🙂 Expected behavior
No error
Bug Report
🔎 Search Terms
union type that is too complex to represent
🕗 Version & Regression Information
TS version: 4.2.3
⏯ Playground Link
Playground link with relevant code
💻 Code
I have a function that should be able to take an object along with a key name that will be present within that object with a specific type, which in this example I hardcode to
stringto simplify the problem:This much works. But when I make my
wrapperparameter a little more complex by wrapping it in DeepReadonly, it fails with the error from the title:DeepReadonly is from ts-essentials:
It doesn't seem like the combination should introduce some large combination of possible union types, but I guess I'm wrong?
🙁 Actual behavior
Error: Expression produces a union type that is too complex to represent
🙂 Expected behavior
No error