Questions tagged [declaration-files]
24 questions
16
votes
1 answer
Typescript Declaration Files for Local JS Files
I am trying add typings for our Javascript files at work while we are in the process of converting to Typescript. However, I can not get the declaration files to be recognized.
Here is my file…

erisman20
- 189
- 1
- 1
- 7
4
votes
0 answers
Why are non-exported types implicitly exported from a TS declaration file with imports but no exports? Is this a bug?
Why are non-exported types implicitly exported from a TS declaration file with imports but no exports? Is this a bug? If not, what is this behavior called and is it documented anywhere?
Background:
I understand that in a TS declaration files with no…

Max Heiber
- 14,346
- 12
- 59
- 97
3
votes
1 answer
Augmenting global in TypeScript
How can I add fetch onto the global object in TypeScript so I don't have to do this:
(global as any).fetch
I've tried this in a file in ./types/index.d.ts
And tried to reference it by including it in the tsconfig.json.

dagda1
- 26,856
- 59
- 237
- 450
3
votes
1 answer
Import webpack externals package in TypeScript with local declaration file
I'm trying to import an external module in my typescript module. In the environment of the web app there already is a module loader and the module "my-lib" is present, which is written in JavaScript and does not ship with a declaration file.
So, I…

Florian Bachmann
- 532
- 6
- 14
3
votes
1 answer
How can I install @types compatible with an older version of TypeScript?
My project uses package like @types/express and @types/body-parser. Recently these .d.ts files were updated to use generic defaults, but that means these declaration files now require TypeScript 2.3 or above.
However, my project still uses an older…

Daniel Rosenwasser
- 21,855
- 13
- 48
- 61
2
votes
1 answer
Writing a declaration file: typescript
How would I write a declaration file for
define(function() {
'use strict';
return Object.freeze({
BTN_LINK: 'btnLink',
COMBO_BOX: 'comboBox',
TEXT: 'text'
});
});

Zlatan Sadibasic
- 101
- 6
1
vote
1 answer
Ambient Typescript Definitions Not Bundled in Library
I'm working with the TSDX tool to build a react-typescript library. I have a number of types exported in my @types/ directory which are clearly picked up by the compiler as I use them within the app with no trouble.
However, during my build, they do…

ABMagil
- 4,579
- 4
- 21
- 35
1
vote
1 answer
TypeScript Declaration File not read while its folder is in typeRoots
In a typescript (Angular 9) project I'm trying to import a private JS lib.
When I import it with import { myMethod } from 'my-private-repo/dist/util'; I get the following error :
Could not find a declaration file for module…

Filteo
- 21
- 2
1
vote
1 answer
Is there any advantage of using declaration files over sources in typescript?
When creating and publishing a library using typescript there are 2 options:
Generate declaration files d.ts together with the bundled javascript file and then in package.json point to it with:
"types": "./dist/mylib.d.ts"
Don't generate the…

Luis Vargas
- 2,466
- 2
- 15
- 32
1
vote
0 answers
How can I provide a hand-authored declaration file in a ts project?
I have these files:
foo.ts
foo.d.ts (hand-authored)
bar.ts
I want to use TypeScript to generate the following output
foo.js
foo.d.ts (same as my hand-authored one)
bar.ts
bar.d.ts
TypeScript ignores my hand-authored foo.d.ts in this case and…

Max Heiber
- 14,346
- 12
- 59
- 97
1
vote
1 answer
Navigating to Angular Sourcecode in VisualStudio?
In my Angular app sourcecode (built using node), I use some type from Angular itself e.g. like this:
import {HashLocationStrategy} from '@angular/common';
When I now try to navigate to the HashLocationStrategy Angular type in VisualStudio, e.g. by…

jfrantzius
- 623
- 7
- 16
1
vote
0 answers
Typescript definition file for scripting host inside desktop application without webframework
I am trying to create a typescript definition file for a javascript for use in a desktop application. I am interested in the intellisense feature of typescript.
The environment where the javascript file is being run is inside another desktop…

MNR
- 11
- 1
0
votes
0 answers
Typescript declaration : how to include node_modules types?
I am trying to include types from node_modules into my .d.ts declaration file.
Currently what I get is this:
declare module "index" { import { Engine } from "@babylonjs/core/Engines/engine"; }
I would like to have all types from Engine declared…

Flapie
- 1
- 2
0
votes
1 answer
I am having trouble with declaration files in TypeScript
I'm trying to use the trace function in my TypeScript code, which has been declared in a .d.ts file as follows:
declare function trace(arg: string | number | boolean);
declare function trace(arg: { id: number; name: string });
However, when I try…

Usama Ahmed
- 21
- 1
- 4
0
votes
0 answers
What is best practice for imports in typescript?
While trying to get a third party node module "mp4frag" to play nice with my typescript code, I tried several solutions as prompted by the error messages from eslint. There didn't appear to be any @types/mp4frag module that I could use. So I tried…

Mark W.
- 25
- 2