I는 다음과 같습니다 기능이있어 :타이프
var myFunction = function (config) {
var example = this.property; // just illustrating that we use `this`
}
myFunction.__reference = 'foobar';
가 지금은 그것을 작성하는 중이 야를 엄격한 타이프 :
interface ExternalScope {
property: string;
}
interface ConfigObject {
name: string,
count: number
}
interface MyFunction {
(XHRLoader: this, cfg: ConfigObject): any;
__reference: string;
}
var myFunction = function (this: ExternalScope, config: ConfigObject): any {
var example = this.property;
}
myFunction.__reference = 'foobar';
위의 코드와
나는 다음과 같은 TypeScipt 오류 얻을 :
Property '__reference' does not exist on type '(this: ExternalScope: config: ConfigObject) => any
을 내 tsconfig.json
의 관련 부분 :
"compilerOptions": {
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"strictNullChecks": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"outDir": "./build",
"allowJs": false,
"target": "es5"
},
당신은 TS에'myFunction'이'MyFunction'의 인스턴스라고 말하지 않았습니다. – deceze
어떻게하면됩니까? 나는 시도했다 : 기능 전에. 하지만 내가 잘못한 점을 생각해보십시오. 오류가 더 많습니다. –
'var myfunction : MyFunction = ...'이 가장 쉬울 것입니다. – deceze