Typescript compiler error when importing json file

后端 未结 6 1643
别跟我提以往
别跟我提以往 2020-12-01 15:50

So the code is simple:

calls.json

{\"SERVER\":{
    \"requests\":{
      \"one\":\"1\"
    }
} }

file.ts

import jso         


        
6条回答
  •  天命终不由人
    2020-12-01 16:03

    This can also be done by using import statement if using webpack v2 which is already packed with json-loader.

    Note that this is not async

    import data from './data.json';//Note that this is not async
    

    Also, in your typings.d.ts file add the following wildcard module to avoid typescript error saying: Cannot find module

    declare module "*.json" {
        const value: any;
        export default value;
    }
    

    For anyone interested in async imports, check this article by 2uality

提交回复
热议问题