Typescript compiler error when importing json file

后端 未结 6 1645
别跟我提以往
别跟我提以往 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

    TS 2.9 added support for well typed json imports. Just add:

    {
      "compilerOptions": {
        "resolveJsonModule": true
      }
    }
    

    in your tsconfig.json or jsconfig.json. Now imports such as:

    import json = require('../static/calls.json');
    

    and

    import * as json from '../static/calls.json';
    

    should be resolved and have proper typings too!

提交回复
热议问题