F
F
felsme2020-10-22 06:10:37
typescript
felsme, 2020-10-22 06:10:37

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.
5f90f7e6aab54883379805.jpeg
5f90f7ec9ed77417737441.jpeg
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

1 answer(s)
A
Alexander, 2020-10-22
@felsme

Apparently - they dug badly . .d.ts-files work for modules.
For example, we have the following structure:

│   main.js
└───lib
        greeting.ts

main.js

import { greeting } from './lib/greeting.js';

console.log(greeting('John'));


greeting.ts

export const greeting = (name: string): string => `Hello, ${name}`;


To generate the required one .d.ts, we can use the following command: tsc lib\greeting.ts --target ES2020 -d. This command will generate two files:
greeting.js

export const greeting = (name) => `Hello, ${name}`;


greeting.d.ts

export declare const greeting: (name: string) => string;


And in the event that you delete greeting.ts, then the type descriptions will be pulled from .d.tsthe file (mostly used in release builds).
Yours .d.tsshould look like this:
export declare class Message {
    send(t: string, f: string): void;
}

5f9107e030050654671624.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question