webstormを利用して、jsonの書き出し方法について調べています。エラーになりうまくコードがかけません。どのように直したらいいのでしょうか。
// sample_json_api.ts
interface APIMapping { [path: string]: Function ; } interface JSONData { [name: string]: JSONData|number|string|boolean| JSONData[]; } class GetData<T> { data: T; } class APIClient { constructor(public mapping: APIMapping) {} get<T extends JSONData>(path: string) { const data: T = this.mapping[path](); // エラー内容 // TS2349: Cannot invoke an expression whose type lacks a // call signature. Type 'GetData()<{}>' has no compatible // call signatures. return new GetData()<T>(data); } } class Person { constructor( public name: string, public age: number ) {} say() { return `${this.name}(${this.age})`; } } // application const client = new APIClient({ "/person/1": Person }); // エラーの内容 Type 'Person' does not satisfy the constraint 'JSONData'. Index signature is missing in type 'Person' const person: Person = client.get<Person>("/person/1").data; console.log(person.say());
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/15 05:11
2018/04/15 05:11
2018/04/15 05:43
2018/04/15 05:44
2018/04/15 05:44
2018/04/15 05:45