Answer the question
In order to leave comments, you need to log in
How to correctly specify the declaration file in ts?
I noticed in different libraries, vscode or webstorm can suggest what data will be from the server or methods of an object that has not yet been created, but how much I haven’t looked into their code I still don’t understand how it works, in typescript in .d.ts files you can describe types , but I do not understand what needs to be done so that text editors start using these files for autocompletion, this is the essence of the issue.
And you don’t need to send me to the dock for ts, I already rummaged through everything there
Answer the question
In order to leave comments, you need to log in
Apparently - they dug badly . .d.ts
-files work for modules.
For example, we have the following structure:
│ main.js
└───lib
greeting.ts
import { greeting } from './lib/greeting.js';
console.log(greeting('John'));
export const greeting = (name: string): string => `Hello, ${name}`;
.d.ts
, we can use the following command: tsc lib\greeting.ts --target ES2020 -d
. This command will generate two files:export const greeting = (name) => `Hello, ${name}`;
export declare const greeting: (name: string) => string;
greeting.ts
, then the type descriptions will be pulled from .d.ts
the file (mostly used in release builds). .d.ts
should look like this:export declare class Message {
send(t: string, f: string): void;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question