TypeScript+SystemJS using JSON and Text plugins

别说谁变了你拦得住时间么 提交于 2019-12-07 00:36:08

问题


Using TypeScript with SystemJS, how can I import a JSON file using plugin-json?

If I write System.import('myjson.json!json').then(...) then it imports it asynchronously and not as a part of System.register([...]).

So, how can I import a JSON file as a part of System.register([...]) and convincing TypeScript to agree to this? (without then Promise syntax).

Note: I'm using the tsc flag -m system


Update:

A possible solution is to use the -m umd option for tsc instead of -m system, then I can do the following:

/// <reference path="typings/requirejs/require.d.ts" />
var myJson = require('myJson.json!json')

However, still waiting for an answer regarding usage of -m system.


回答1:


In order to do : import json = require('myJson.json!json') You need to have some .d.ts file with the following:

declare module 'myJson.json!json'{
   var json:any;
   export = json;
}


来源:https://stackoverflow.com/questions/30962590/typescriptsystemjs-using-json-and-text-plugins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!