Typescript declaration for Node module package

126 Views Asked by At

I'm trying to add a TS delcaration for a package i'm using. The package itself doesn't have any TS declarations.

I'm using VS Code, and it throws the warning

 Try `npm i --save-dev @types/picoapp` if it exists or add a new declaration (.d.ts) file containing `declare module 'picoapp';`

So i added the following to reference methods build in. In a Picoapp.d.ts file

declare module 'picoapp' {
  export type Context = {
    on: (event: string | string[], method: CallableFunction) => void,
    emit: (event: string | string[], data?: object | Function) => void,
    hydrate: (object: object) => void,
    getState: () => any,
  };
}

But with above, and using the Context reference, it insists on importing the Context from the package like this:

import { Context } from 'picoapp' How do you get around that, seems risky that it attaches itself on the package... Just thinking in case of they adding a method called Context later on, then what happens

0

There are 0 best solutions below