Unable to find more appropriate language to elaborate beyond the title, I'm going to rely on the code itself:
let var1 = someExternalLibraryMethod(); // assume var1 is implicitly Promise<string>
let var2: typeof var1; // this approach enables me to "link" the types of both variables without explicitly defining them as the same type (e.g. let var2: Promise<string>;)
let var3: ???????; //I aim to align this type with the "inner" type of var1 without specifying it directly (e.g. instead of let var3: string;)
The selection of Promise<string>
was random. I am seeking a method that can be applied to other instances of generic types, such as rxjs.Observable<number>
and
mongoose.Schema<{_id: number}>
.
This methodology should function without the need for hardcoding the "outer" type. In other words, the term 'Promise' should not be explicitly mentioned. If TypeScript indeed supports this capability, my assumption is that the syntax might resemble something like
let var3: InnerTypes<typeof var1>[0]; // This is a speculative attempt and may not actually work
TypeScript version: 3.x