Is there any way to remove declaration?

49 Views Asked by At

I use a library which in its declaration file index.d.ts has:

declare namespace browser.runtime
{
    ...
    function sendMessage(message: any, options?: _SendMessageOptions): Promise<any>;
    function sendMessage(extensionId: string, message: any, options?: _SendMessageOptions): Promise<any>;
    ...
}

There is any way to remove those declarations? To be more precisely I want to remove any from it.


I know that I can add overload, but that doesn't satisfy me:

declare namespace browser.runtime
{
    function sendMessage(message: any, options?: _SendMessageOptions): Promise<unknown>;
}
1

There are 1 best solutions below

1
rveerd On

You can create your own type declarations.

  • Create a new folder for your type declarations. You can use any name, for example types.
  • Create a declaration file in this folder. You can use any name, for example some-library.d.ts. In your case, you can copy the file from @types/some-library and make your changes.
  • Edit your TypeScript configuration. I assume you are using tsconfig.json. Add the following:
"typeRoots": [
  "./types",
  "./node_modules/@types",
],
  • You can uninstall @types/some-library.