ts-morph

Ambient

Certain nodes in TypeScript can be ambient. For example, all nodes within a declaration file are ambient.

Testing if ambient

Use isAmbient():

classDeclaration.isAmbient(); // returns: boolean

This will do several checks to see if it's an ambient declaration.

declare keyword

Check for the declare keyword:

classDeclaration.hasDeclareKeyword(); // returns: boolean

Or get the declare keyword if it exists:

classDeclaration.getDeclareKeyword();

Or set if it has a declare keyword:

classDeclaration.setHasDeclareKeyword(true);
classDeclaration.setHasDeclareKeyword(false);