I'm trying to stop using TSD for obtaining type definitions in a project that uses many libaries via global variables (the outFile
option is used in tsconfig.json
if this matters). In particular, it uses the Moment library in this way. Moment provides its own type definitions as part of the NPM package. However, these definitions don't declare anything in the global scope. Note that moment
is both a global variable of type moment.MomentStatic
and a type namespace at that. Using the NPM package, how can I augment the global scope in such a way that everything starts working as it works now with the old type definitions got from TSD? Namely, moment
should be available globally, in any file, as both a variable and as a type namespace. Basically, what I want is something along these lines:
import * as _moment from 'moment';
declare global {
const moment: _moment.MomentStatic;
import moment = _moment;
}
This doesn't compile:
[ts] Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.
[ts] Import declaration conflicts with local declaration of 'moment'
Is there a workaround?