Typescript instanceof运算符失败

时间:2016-09-21 09:15:51

标签: angular typescript

我正在Angular 2应用程序中编写一些继承代码:

reportColumnSet.ts:

import { Equatable } from './../../core/equatable';

export abstract class ReportColumnSet implements Equatable<ReportColumnSet> {

    constructor(public name: string) {
    }

    public abstract equals(other: ReportColumnSet): boolean;
}

reportNumberColumnSet.ts:

import { ReportColumnSet } from './reportColumnSet';

export class ReportNumberColumnSet extends ReportColumnSet {

    constructor(public name: string) {

        super(name);
    }

    public equals(other: ReportColumnSet): boolean {

        ...
    }
}

reportColumnSets.service.ts:

...    
import { ReportColumnSet, } from './reportColumnSet';
import { ReportNumberColumnSet } from './reportNumberColumnSet';

@Injectable()
export class ReportColumnSetsService {

    public getReportColumnSets(): Observable<Array<ReportColumnSet>> {

        const actual = new ReportNumberColumnSet('Actual');
        ...

        return Observable.of([actual, ...]);
    }
}

然后在调用方法中:

import { ReportNumberColumnSet } from './../columnsets/reportNumberColumnSet';
...
const columnSetsService = new ReportColumnSetsService();

return Observable.forkJoin(columnSetsService.getReportColumnSets(), ...)
    .map(results => {

     const columnSets = results[0];
     var t = columnSets[0] instanceof ReportNumberColumnSet;
     ...
});

t是假的!,但即使在(Visual Studio)调试器中,它确认columnSets [0]是一个Object(ReportNumberColumnSet),所有__proto__看起来都很好。

(...是我删除了一些无关代码的地方)

我尝试了很多变化和调试,把头发拉出来!

它可能是System js中的东西吗?

原始javascript看起来像这样:

var reportNumberColumnSet_1 = require('./reportNumberColumnSet');
...
var actual = new reportNumberColumnSet_1.ReportNumberColumnSet('Actual');

0 个答案:

没有答案