에서 인덱싱 가능한 객체 0.9.5로 업데이트 한 후 js-library에 대한 defenition에서 몇 가지 오류를 발견했습니다. 코드를 통해 상황을 설명하겠습니다. 그것은 내 자바 스크립트 코드 :최신 타이프 스크립트 컴파일러 버전 (0.9.5)
var Sample = lib.ClassImpl({
ctor: function(array) {
var me = this;
this._items = array;
this._items.forEach(function(name) {
me[name] = new ItemWrapper(name); //Implemetation of ItemWrapper is unnecessary
});
},
doSomething: function() {
//some logic
},
returnSomething: function() {
return this._items.length;
}
});
그리고 이것은 사용이다 : 나는 할 수 있었다 타이프 라이터 컴파일러의 이전 버전 (0.9.1.1)에 대한 쓴 한 타이프 라이터 defenitions에서
var sample = new Sample(["First", "Second", "Third"]);
sample.doSomething();
console.log(sample.returnSomething());
console.log(sample.First.method());
console.log(sample.Third.method());
(인텔리이 마법처럼 작동)
export interface ISampleBase {
doSomething(): void;
returnSomething(): number;
}
export interface ISample extends ISampleBase {
[name: string]: ItemWrapper; //here is the error
}
export class Sample implemets ISampleBase {
constructor(array: string[]);
doSomething(): void;
returnSomething(): number;
}
을 그리고 내 TS-파일에서 사용 : 할
,369을var sample: ISample = new Sample(["First", "Second", "Third"]);
sample.doSomething();
sample["Third"].method();
그러나 버전 0.9.5로 업데이트 한 후 모든 명명 된 속성은 코멘트로 표시된 줄 위의 문자열 인덱서 유형 ItemWrapper의 하위 유형에 따라야한다는 오류가 있습니다. 문제를 해결할 수있는 변형이 있습니까?
TypeScript playground with example.
그래서 더 이상 합법적이지 않아서 결국 어떻게 됐는지 궁금합니다. d.ts 파일과 비슷한 문제가 있습니다. – Travis