I am facing an issue with my Angular 7 app where I need to include some typed JS constants from outside of the project. These constants are essential for the AngularJS app and need to be kept in a separate js file. I have defined a new path in the tsconfig.json file:
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"baseUrl": "src",
"paths": {
"@app/*": ["app/*"],
"@env/*": ["environments/*"],
"@dep/*": ["../../web-common/*"]
}
}
}
In the @dep folder, I have test.js and test.d.ts files that contain the following:
export const TEST_CONST = {
parser: 'CSV',
styler: 'XVE'
};
and
export interface TEST_CONST {
parser: string;
styler: number;
}
However, when trying to import it using:
import {TEST_CONST} from '@dep/constants/test';
...
console.log(TEST_CONST.styler);
It throws the error:
error TS2693: 'TEST_CONST' only refers to a type, but is being used as a value here.
I also attempted to import '@dep/constants/test.js' without success. How can I import a js file with typings into an Angular app? It seems like this should be possible.