Our TS application utilizes a JavaScript library, for which we crafted a .d.ts file to integrate it with TypeScript. Initially, the file resided in a "typings" directory within the project and everything operated smoothly. Subsequently, we opted to relocate these typings to a separate repository to facilitate sharing across multiple projects.
The problem arises post the relocation of typings to an external repository; the IDEs (Idea and VSCode) fail to recognize properties and methods from the super type. Interestingly, despite the IDEs indicating errors, the application compiles, runs, and all functionalities operate as expected.
Do you have any insights on how to address this issue?
The structure of the typing repository is as follows:
-custom-typings
- index.d.ts
- tsconfig.json
- package.json
package.json:
{
"name": "custom-typings",
"author": "Author Name",
"version": "0.1.3",
"types": "./index.d.ts",
"dependencies": {
"typescript": "next"
}
}
tsconfig:
{
"compilerOptions": {
"target": "ES2015",
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"esModuleInterop": true,
"alwaysStrict": true,
"lib": [
"ES2015",
"ES2016",
"dom"
],
"pretty": true,
"moduleResolution": "node",
"module": "ES2020"
},
"exclude": [
"dist",
"node_modules",
],
"typeAcquisition": {
"enable": true
}
}
index.d.ts
declare module 'custom-typings' {
export class A {
aMethod();
}
export class B extends A{
bProperty: any = {foo: 'Foo'};
}
const CustomTypes: {
B: typeof B;
};
export default CustomTypes
}
Utilizing the types:
import CustomTypes from 'custom-typings';
class MyComponent extends CustomTypes.B {
init() {
console.log(this.bProperty.foo); // property 'bProperty' does not exist in type MyComponent
this.aMethod(); // property 'aMethod' does not exist in type MyComponent
}
}