Skip to content

Conversation

@christopherswenson
Copy link
Contributor

We can define a type Prettify<T>

type Prettify<T> = {
  [K in keyof T]: T[K];
} & {};

which computes/flattens a type.

This turns a compiler error like Object literal may only specify known properties, and 'foo' does not exist in type 'RecordExtTypeDef<FunctionParameterTypeExtensions>'.ts(2353) into Object literal may only specify known properties, and 'foo' does not exist in type '{ type: "record"; fields: ExtFieldDef<FunctionParameterTypeExtensions>[]; }'.ts(2353), which is maybe more helpful.

We could theoretically even do DeepPrettify<T>, but this gives us less control over what things get computed...

type DeepPrettify<T> = {
  [K in keyof T]: DeepPrettify<T[K]>;
} & {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants