当我在运行
时尝试使用带有definetly类型界面的外部javascript文件时,我使用angular 2 aot compile编译错误{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"files": [
"tmp/app/app.module.ts",
"tmp/app/main.ts"
],
"angularCompilerOptions": {
"genDir": "tmp/aot",
"skipMetadataEmit" : true
}
}
我的tsconfig-aot.json:
node_modules/.bin/ngc -p tsconfig-aot.json
Error at (...) public/tmp/app/services/service-messaging-stomp.ts:77:26: Cannot find name 'StompClient'.
Error at (...) public/tmp/app/services/service-messaging-stomp.ts:79:39: Cannot find name 'StompSubscription'.
...
错误讯息:
"use strict";
/// <reference path="./stomp.d.ts"/>
service-messaging-stomp.ts文件引用了stomp.d.ts:
private stompClient: StompClient;
private path: string;
private uiDeviceEventSubsription: StompSubscription = null;
从第77行到第79行:
// Type definitions for Stomp
// Project: https://stomp.github.io/
// Definitions by: Daniel Kis <https://github.com/kisdaniel>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../../../typings/tsd.d.ts"/>
interface StompArguments {
port: number;
host: string;
debug: boolean;
login: string;
passcode: string;
}
interface StompSendArguments {
destination?: string;
body?: string;
persistent?: string;
transaction?: string;
priority?: number;
}
interface StompHeaders {
[key: string]: string;
login?: string;
passcode?: string;
}
interface StompTransaction {
id: string;
commit(): void;
abort(): void;
}
interface StompErrorHeader {
message: string;
}
interface StompError {
headers: StompErrorHeader;
}
interface StompStatic {
over(socket: SockJS): StompClient;
overTCP(host: string, port: number): StompClient;
overWS(url: string): StompClient;
client(url: string): StompClient;
}
interface StompMessage {
body: string;
}
interface StompSubscribeHeaders {
[key: string]: string;
id: string;
ack: string;
}
interface StompSubscription {
unsubscibe(): void;
}
interface Heartbeat {
outgoing: number;
incoming: number;
}
interface StompClient {
constructor(args: StompArguments): void;
connect(login: string, passcode: string, connectCallback: () => (void)): void;
connect(login: string, passcode: string, connectCallback: () => (void), errorCallback: (error: StompError) => (void)): void;
connect(login: string, passcode: string, connectCallback: () => (void), errorCallback: () => (void), host: string): void;
connect(headers: StompHeaders, callback: (frame: string) => (void)): void;
connect(headers: StompHeaders, callback: (frame: string) => (void), errorCallBack: () => (void)): void;
on(event: string, callback: (param: any) => (void)): void;
subscribe(queue: string, callback: (message: StompMessage) => (void), headers: StompSubscribeHeaders): StompSubscription;
subscribe(queue: string, callback: (message: StompMessage) => (void)): StompSubscription;
send(params: StompSendArguments): void;
send(path: string, params: StompSendArguments): void;
send(path: string, params: StompSendArguments, message: string): void;
begin(): StompTransaction;
disconnect(): void;
heartbeat: Heartbeat;
}
declare var Stomp: StompStatic;
stomp.d.ts位于同一目录中,但似乎它不使用此文件,因为它无法识别StompClient和StompSubscription类型。
有人能告诉我如何使用具有角度AOT编译的definetly类型引用? (它适用于JIT编译)
我的stomp.d.ts文件:
@Echo Off
SetLocal EnableDelayedExpansion
Set File=testfile
For /F "Tokens=1* Delims=:" %%A In ('FindStr/N "^" "%File%.txt"'
) Do Set/A "_=%%A%%2"&>>%File%_!_!.txt Echo(%%B
<%File%_0.txt (For /f "delims=" %%A in (%File%_1.txt) Do (
Set "B="&Set /P "B="
Echo(!B!
Echo(%%A
)) >%File%-new.txt
Del %File%_*