W
W
Wasya UK2018-06-23 20:18:33
Node.js
Wasya UK, 2018-06-23 20:18:33

How to declare a module in TypeScript?

This is the first time I've encountered this problem, and I don't really understand how it is solved. Found something like:
jquery.d.ts

declare let $: JQuery;
export default $;
,
but I do not quite understand how to write it correctly and where.
npm didn't find the declaration npm i --save-dev @types/mongoose-beautiful-unique-validation for it .
I write a server on a node using typescript, then I compile it into .js, in the src directory with the server file I created the src/server.d.ts file and wrote the following there:
declare module 'mongoose-beautiful-unique-validation';
export default require('mongoose-beautiful-unique-validation');

But I get an error: declare module 'mongoose-beautiful-unique-validation
How to properly declare such files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ermolaev, 2018-06-28
@ermolaevalexey

It is possible to prescribe the source of typings in tsconfig.json. It will be more convenient to create some directory in the root, for example typings, and put all custom *.d.ts files in it. However,
the problem here is that this will remove support for other typings from ` @types/* ` and will need to be added to the array manually.

{
   "compilerOptions": {
       "typeRoots" : ["./node_modules/@types", "./typings"]
   }
}

https://www.typescriptlang.org/docs/handbook/tscon...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question