So if I understand you correctly, you want to define the types of a library that don't necessarily have a .d.ts file.
I did start doing this for a database I was using called rethinkdb some time ago now. (https://www.npmjs.com/package/rethinkdbdash)
Just as a warning, there are a few any
references in here but that's purely because this was POC at the time but you should hopefully get the general idea of what I was trying to achieve.
declare module 'rethinkdbdash' {
export default function RethinkDBDash(config: ConnectionConfig): RethinkConnection
interface ConnectionConfig {
host?: string;
port?: number;
db?: string;
}
export interface RethinkConnection {
table(document: string): Term;
asc(columnName: string): Term;
desc(columnName: string): Term;
}
interface filterQueryParams {
[key: string]: string;
}
interface Row {
(fieldName: string): Term;
}
interface Term {
insert(documents: any, options?: any): void;
filter(filterParams: filterQueryParams): any; //@todo change the return type
update(callback: (row: Row) => void): Term;
append(document: any): Term;
pluck(...columnNames: string[]): Term;
limit(amount: number): Term;
orderBy(fieldName: string): Term;
orderBy(obj: any): Term;
run(): any;
}}
The above was a file called rethink.d.ts within a folder called typings.
You can basically think of this as my contract of how I expect to interact with the underlying library.
The other thing you have to do is tell the TypeScript compiler that you have defined these types for the library and you do that by specifying the following in tsconfig.json
within the compilerOptions block
"typeRoots": ["./node_modules/@types", "./src/**/typings"],
What this tells the compiler is - still honour the types that are within node_modules but also include any custom definitions that I've created within the project.
Once you've got this setup you should find the intellisense in the IDE pick up these definitions for you.
I hope this is able to unblock you