Support for import.meta
TypeScript 2.9 introduces support for import.meta
, a new meta-property as described by the current TC39 proposal.
The type of import.meta
is the global ImportMeta
type which is defined in lib.es5.d.ts
.This interface is extremely limited.Adding well-known properties for Node or browsers requires interface merging and possibly a global augmentation depending on the context.
Example
Assuming that __dirname
is always available on import.meta
, the declaration would be done through reopening ImportMeta
interface:
// node.d.ts
interface ImportMeta {
__dirname: string;
}
And usage would be:
import.meta.__dirname // Has type 'string'
import.meta
is only allowed when targeting ESNext
modules and ECMAScript targets.