What declare in `export declare type Xyz` means vs` export type Xyz`
Right. The keyword declare
is useful when you need to say that there will be a variable or constant at runtime.
Example. Let's say you want to import a library someExternalLib
, but it's not on npm (you need to manually include it using the script tag). You know that it will be available as a global variable someExternalLib
with functions fun1
and fun2
. The problem is that Typescript doesn't know why you need it by declaring a global someExternalLib
:
declare const someExternalLib: { fun1: () => number, fun2: () => number }
This is usually needed in definition files to declare variables, constants, classes, functions. It is redundant for types and interfaces.
source to share