In Typescript, there is a Partial<Object>
type that allows all fields of an object to be optional.
Can we create a generic type Promisify<Person>
in the same way, transforming the Person
type from:
interface Person {
getName(): string;
getAge(): number;
}
to:
interface PromisifyPerson {
getName(): Promise<string>;
getAge(): Promise<number>;
}
I have a synchronous API defined using Typescript interfaces and my aim is to generate an asynchronous version of the API without having to rewrite every interface. Here's another example:
interface ApplicationApi {
startApp(): void;
readFile(fileName): string;
}
type AsyncApplicationAPI = Async<ApplicationApi>
After this transformation, I anticipate that AsyncApplicationAPI will look something like:
interface AsyncApplicationApi {
startApp(): Promise<void>;
readFile(fileName): Promise<string>;
}