sagen, ich bin ein Modul des Typs mit:Typoskript typisieren vorhandene Variable
interface AwesomeLibrary {
name: string;
query: Object;
}
I query
in eine andere Schnittstelle typisieren wollen:
interface Query {
startDate: string;
endDate: string;
showAll: boolean;
}
Lassen Sie uns sagen, dass es eine Callback-Funktion ist, dass gibt mir die AwesomeLibrary
. Ich möchte dann die query
in Query
tippen. Im Moment ist das alles was ich habe:
functionCb(response: AwesomeLibrary) {
// This works fine
let query: Query = response.query as Query;
// Now, query.startDate is available
// Do stuff to query
// At the end, I want to send response back to another function, so I do
response.query = query;
otherFunction(response);
// This does not work, but basically what I want:
response.query = response.query as Query;
// Then do stuff to response.query directly
// Here response.query.startDate is not available, instead I have to use response.query['startDate']
// Even this does not work:
let query: Query = response.query as Query;
response.query = query;
}
Gedanken?