다음과 같이 내가 BMW라는 클래스가 BMW.ts에서 정의한 다음과 같이 나는 정의 자동차 및 것 수업을 다른 파일 Thing.ts에서타이프 라이터 내부 모듈 사용
///<reference path="../Thing.ts"/>
module Entities.Cars {
import e = Entities;
export class BMW extends Vehicle {
public series: string;
constructor (model : string, series : string) {
super("BMW", model)
this.series = series;
}
drive() {
alert("driving a bimmer is a different kind of feeling");
}
toString() : string
{
return this.getName() + " " + this.series + " " + this.getType();
}
}
}
:
module Entities {
// Class
export class Thing {
private _name: string;
private _type: string;
// Constructor
constructor (public name: string, public type: string) {
this._name = name;
this._type = type;
}
getName(): string { return this._name; }
setName(name: string) { this._name = name; }
getType(): string { return this._type; }
setType(name: string) {
this._type = name;
}
toString() : string
{
return "Entities.Thing";
}
}
export class Vehicle extends Thing {
public cargoCapacity: number;
public fuelType: string;
public owner: string;
constructor (make: string, model : string) {
super(make, model)
}
drive() {
}
toString(): string {
return "Entities.Vehicle";
}
}
}
나는 것와 BMW 타이프 스크립트 파일을 참조 뒤에 다음 코드를 실행하려고 시도 :
var car = new Entities.Cars.BMW("335i", "E90");
car.drive();
나는 제외를 얻을 수 다음 오류 "Microsoft JScript 런타임 오류 : 'BMW'속성 값을 가져올 수 없습니다 : 개체가 null이거나 정의되지 않았습니다." 생성 된 Javascript for BMW에 오류가 있습니다. 위의 스 니펫에 무엇이 잘못 되었습니까?
그게 다야, 고마워. app.js에서 Thing.js와 BMW.js를 참조하지 않았습니다. 현재 TypeScript 컴파일러는 다음과 같이 프로젝트 파일에 구성되어 있습니다. . 모든 것을 tsc --out app.js app.ts로 변경합니까? –
은 컴파일러 옵션 -out scripts \ app.js scripts \ app를 전달했습니다.ts 및 모든 코드가 포함 된 단일 자바 스크립트 파일을 참조하십시오. 하지만, 내가 참조하는 것이 app.js라면 엔티티는 정의되지 않은 상태가됩니다 ... –
이전에 어떤 일이 발생했는지 모릅니다. 옵션 1은 현재 잘 작동합니다. 다시 한 번 감사드립니다. –