TypeScript + SystemJS使用JSON和Text插件 [英] TypeScript+SystemJS using JSON and Text plugins
问题描述
将 TypeScript 与 SystemJS 一起使用,如何使用 plugin-json $ c导入 JSON 文件$ c>?
Using TypeScript with SystemJS, how can I import a JSON file using plugin-json
?
如果我写 System.import('myjson.json!json')。那么(...)
然后它以异步方式导入它,而不是 System.register([...])
的一部分。
If I write System.import('myjson.json!json').then(...)
then it imports it asynchronously and not as a part of System.register([...])
.
那么,如何将JSON文件作为 System.register([...])
的一部分导入并说服 TypeScript 同意这个? (没有然后
承诺语法)。
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).
注意:
我正在使用 tsc
标志 -m system
可能的解决方案是使用 -m umd
选项 tsc
而不是 -m system
,然后我可以执行以下操作:
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')
然而,还在等待有关使用 -m system
的答案。
However, still waiting for an answer regarding usage of -m system
.
推荐答案
要做: import json = require('myJson.json!json')
你需要一些 .d.ts
具有以下内容的文件:
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;
}
这篇关于TypeScript + SystemJS使用JSON和Text插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!