For example, my project has a dependency on npm package foo-js, and dev-dependency @types/foo-js for type definitions.
// package.json
{
...
"dependencies": {
"foo-js": "2.0.0" // latest
},
"devDependencies": {
"@types/foo-js": "1.2.3" // latest
}
}
The version of @types/foo-js is outdated (though it is the latest), If I try to use newly added method of foo-js;
import { Foo } from 'foo-js'
Foo.v1_method() // ok
Foo.v2_new_method() // Property 'v2_new_method' does not exist on type 'typeof import("foo-js")'.ts(2339)
Using type assertion such as (Foo as any).v2_new_method() solves compile-time eror, but I'm trying not to use type assertions as much as possible.
I've tried to add type declaration file as below;
// types.d.ts
declare module 'foo-js' {
interface Foo {
v2_new_method: () => any
}
}
but it didn't work. I think I've missed something.
Is there another way to solve this problem?