What does declare in `export declare type Xyz` mean vs `export type Xyz`

Correct. declare keyword is useful when you need to say that there will be a variable or constant at execution time.

Example: Let’s say you want to import library someExternalLib, but it is not on npm (you have to manually include it via script tag). You know that it will be accessible as global variable someExternalLib with functions fun1 and fun2. The problem is that Typescript doesn’t know – that’s why you have to help it by declaring the global someExternalLib:

declare const someExternalLib: { fun1: () => number, fun2: () => number }

This is usually necessary in definition files to declare variables, constants, classes, functions. It is redundant for types and interfaces.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)