Whenever tsc
generates d.ts
files, it includes declare
word there, like this:
export declare class Moment {
name: string;
}
Now, declare
in ts
files is used to say to tsc
that no js
should be generated for the type with declare
. So it makes sense in the ts
files. However, no js
is generated from d.ts
files anyway, why use the word there?
I tried to remove declare
word from the above code:
export class Moment {
name: string;
}
and it worked the same.
I've found the following here:
If a file has the extension .d.ts then each root level definition must have the declare keyword prefixed to it. This helps make it clear to the author that there will be no code emitted by TypeScript. The author needs to ensure that the declared item will exist at runtime.
So is it the only purpose of the declare
in d.ts
files?
Plese note, this is not the same question as this one, as my question is about using declare
in d.ts
files, not ts
files.