I'm really getting crazy because I can't find a solution for this. What I want to archive is to import a JSON file with a configuration into my TypeScript file. I've learned that I need a declaration file. So I've added a file json-loader.d.ts into my project. I also tried it at several levels (root, typings folder, custom_typings folder) because this are the solutions I've found. The file content looks like this:
declare module "json!*" {
let json: any;
export = json;
}
declare module "*.json" {
const value: any;
export default value;
}
But the compiler still tells me, that it is not possible to import the JSON file, because it isn't a module. So, how is the compiler getting aware, that there is such a declaration file?
I already tried to modify my tsconfig.json like this:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "dist",
"typeRoots": [
"./node_modules/@types",
"./typings"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
But it still doesn't work. Any suggestions?
Thanks!
import * as config from '../config.json'. Should work when JSON is handled like a module I guess...