I'm trying to use declare
with WebPack, but instead of leaving the variable names alone, it adds _script_project__WEBPACK_IMPORTED_MODULE_0__
in front of it during compilation. This causes the variables to be undefined. Does anyone know how to solve this? Thank you!
project.ts
export declare namespace Module
{
class Project{
constructor()
}
}
index.ts
import { Module } from "./script/project"
const project = new Module.Project()
alert(project)
UPDATE
Well, I figured it out. Webpack creates an object for each module which contains the exported variables even if you use the declare
keyword. This means that in other modules these variables will get _script_project__WEBPACK_IMPORTED_MODULE_X__
in front of it. You can fix this by removing export
or by using global scope through the global
variable.