Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom typings files to angular 6

I am trying to ad some custom typings definition file in angular but facing some error.

in app folder I have external folder in which I have external.d.ts file and below code

declare function format(input: string, ...args): string;

in tsconfig.json I tried adding "files": ["/app/external/external.d.ts"]

but its not working.

can somebody give me idea about adding custom typings file to angular 6.

like image 637
Prasad Avatar asked Aug 16 '18 12:08

Prasad


People also ask

Where do you put custom types in TypeScript?

To do this you should edit the tsconfig. json file, and add the typeRoots property under the compilerOptions property. When the property is excluded, TypeScript is automatically searching for types in the node_modules/@types folder of your project.

What is Typings in angular?

Typings describes contract of libraries you use. This allows the TypeScript compiler that what you use exist (classes, properties, ...). You can install typings from a repository using the typings command or let the compiler find out them leveraging the strategy specified in the tsconfig.

Why we use ts file in Angular?

TypeScript is a primary language for Angular application development. It is a superset of JavaScript with design-time support for type safety and tooling.

What is tsconfig json file in Angular?

json file is a file of JSON format which allows us to point the root level files and different compiler options to setup that require to compile a TypeScript based projects. The existence of this file in a project specifies that the given directory is the TypeScript project folder root.


2 Answers

Add the custom typing file to typeRoots in tsconfig.json in the root folder work for me.

"typeRoots": ["node_modules/@types", "src/typings.d.ts"],
like image 69
Jun Avatar answered Sep 19 '22 13:09

Jun


The correct property is types inside tsconfig.json:

enter image description here

like image 39
dannrob Avatar answered Sep 17 '22 13:09

dannrob