Reputation: 11
having:
// api.js
export function getLayout(){
return axios.get('/api/layout').then(res => res.data)
}
// api.d.ts
declare interface JSONResponse {
meta: object,
data: Array<Field>
}
export declare function getLayout():Promise<any> // Promise<any>.then<JSONResponse>??
i want VSCode to suggest the following
getLayout().then(json => {
json.data // suggest data is of type Array<Fields>
})
is this possible?
Upvotes: 1
Views: 204
Reputation: 141632
If I understand correctly, then this will meet your requirement.
// api.d.ts
declare interface JSONResponse {
meta: object,
data: Array<Fields>
}
export declare function getLayout(): Promise<JSONResponse>
// client.ts
var data = getLayout().then((json) => {
json.data;
});
Here is an image of the suggestion in the TypeScript playground:
Upvotes: 1