Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mapped type compiler error when strict is true: Mapped object type implicitly has an 'any' template type

I have a mapped type:

export type Errors<T> = {
  [P in keyof T]?
}

strict is set to true in tsconfig.json and I get this error:

Mapped object type implicitly has an 'any' template type.

How can I get rid of this error without setting strict to false or disabling the error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are missing the type, so the default is for the mapped type to implicitly be any for all props. But under noImplictAny which is part of strict, TypeScript will not implicitly assume any

The simplest solution is to specify a type. To keep existing behavior you can use any but maybe consider a stricter type if possible.

export type Errors<T> = {
  [P in keyof T]?: any
}

Playground Link

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading