Typescript definitions for core-js@3

Viewed 151

I need to use some core-js@3 polyfills from within TypeScript. However, @types/core-js provides definitions for core-js@2.5 only, and it seems that core-js@3 is sufficiently different from 2 that most type definitions are outdated. Is there some accepted workaround to this?

1 Answers

A shim can help here. For instance, if you need typings for structuredClone:

// shims/core-js.d.ts

declare module 'core-js/actual/structured-clone' {
    export default function structuredClone<T>(value: T): T;
}

Note: This omits the transfer property as it's not something I personally intend to use.

Related