I have a function named filterNil
:
export function filterNil<T extends object>(obj: T): NonNullable<T> {
return Object.fromEntries(Object.entries(obj).filter(([_, v]) => ![null, undefined, ''].includes(v)));
}
The Object.fromEntries
throws a TS type error:
Property 'fromEntries' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.(2550)
The error message is clear, How can I add es2019
lib to compilerOptions.lib
option in TypeScript Playground?
CodePudding user response:
It appears that the playground chooses what library declarations to include based on the target.
If you change Target:
to es2019
or later it works.
Description from the TS config menu:
Target: Set the JavaScript language version for emitted JavaScript and include compatible library declarations.