有人知道如何使用Ts1.5导入外部模块吗?
文档并没有真正清楚,似乎:
import { Reflector } from '../node_modules/reflect-metadata/Reflect';
不起作用。 (Reflect-metadata公开Reflector.ts和d.ts文件)
我不知道如何处理导入外部模块,即使它们是基于打字稿或基于es6的......
你能帮助我吗?
编辑:
[11:23:40] Compiling TypeScript files using tsc version 1.5.0
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
5,24): error TS2304: Cannot find name 'Map'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
5,37): error TS2304: Cannot find name 'Map'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
5,58): error TS2304: Cannot find name 'Map'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
6,24): error TS2304: Cannot find name 'Set'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
6,37): error TS2304: Cannot find name 'Set'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
6,58): error TS2304: Cannot find name 'Set'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
7,28): error TS2304: Cannot find name 'WeakMap'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
7,45): error TS2304: Cannot find name 'WeakMap'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
7,70): error TS2304: Cannot find name 'WeakMap'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(4
6,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(8
3,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
24,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
05,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
48,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(2
85,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(3
26,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(3
51,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(3
83,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(4
19,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(4
44,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(4
76,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(5
12,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(5
37,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(5
69,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(6
05,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(6
30,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(6
62,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(6
98,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(7
22,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(7
53,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(7
88,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(8
12,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(8
43,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(8
78,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(9
03,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(9
35,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(9
71,21): error TS2384: Overload signatures must all be ambient or non-ambient.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
039,99): error TS2304: Cannot find name 'Map'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
269,40): error TS2304: Cannot find name 'Map'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
291,59): error TS2304: Cannot find name 'Map'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
327,30): error TS2304: Cannot find name 'Set'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
337,59): error TS2304: Cannot find name 'Set'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
374,46): error TS2304: Cannot find name 'WeakMap'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
408,33): error TS2304: Cannot find name 'msCrypto'.
[11:23:42] [tsc] > F:/nodejs/Sugar.io/node_modules/reflect-metadata/Reflect.ts(1
409,21): error TS2304: Cannot find name 'msCrypto'.
[11:23:42] Failed to compile TypeScript: Error: tsc command has exited with code
:2
答案 0 :(得分:2)
Reflect.ts
的编码方式(作为非导出的内部模块)意味着您无法直接从中导入成员。您必须明确使用.d.ts
文件并纯粹导入库以产生副作用:
/// <reference path="../node_modules/reflect-metadata/reflect-metadata.d.ts" />
import '../node_modules/reflect-metadata/Reflect';