Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use types declaration on another package

I have setup a private NPM registry hosting a fork of a publicly available package (which is allowed by the package's licence).

The source package has a type declaration provided by the wonderful DefinitelyTyped project.

Currently, in my project, if I write:

import mypackage from '@private/mypackage'

The types provided by DefinitelyTyped (@types/mypackage) will not apply, and I will get the error:

error TS7016: Could not find a declaration file for module '@private/mypackage'. 'node_modules/@private/mypackage/index.js' implicitly has an 'any' type.

In my project, is it possible to redeclare the source package types for the fork, so that the above example will work?

like image 339
GnxR Avatar asked Sep 18 '26 12:09

GnxR


1 Answers

You can add a declaration file (.d.ts) for the module:

declare module '@private/mypackage'
{
    import m from 'mypackage';

    export default m;
}
like image 178
H.B. Avatar answered Sep 20 '26 08:09

H.B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!