Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

typescript get the promise return type

type AsyncReturnType<T extends (...args: any) => any> =
	T extends (...args: any) => Promise<infer U> ? U :
	T extends (...args: any) => infer U ? U :
	any
Comment

typescript get type from promise

function promiseOne() {
  return Promise.resolve(1)
}
    
const promisedOne = promiseOne()
    
// note PromiseLike instead of Promise, this lets it work on any thenable
type ThenArg<T> = T extends PromiseLike<infer U> ? U : T
    
type PromiseOneThenArg = ThenArg<typeof promisedOne> // => number
// or
type PromiseOneThenArg2 = ThenArg<ReturnType<typeof promiseOne>> // => number
Comment

Get Promise type TypeScript

//return from promise
type promiseReturn<T extends Promise<unknown>> = T extends Promise<infer type>
	? type extends Promise<unknown>
		? promiseReturn<type>
		: type
	: never;
type prom = promiseReturn<Promise<string>>; //string
type prom_2 = promiseReturn<Promise<Promise<string>>>; //string
Comment

PREVIOUS NEXT
Code Example
Typescript :: regex exec returns null 
Typescript :: python remove all double elements from list 
Typescript :: python get elements from list of dictionaries 
Typescript :: react redux typescript 
Typescript :: angular validations 
Typescript :: react fc typescript 
Typescript :: nest js http exceptions 
Typescript :: no corners in broder css 
Typescript :: switch in typescript 
Typescript :: c# to typescript 
Typescript :: what is typescript in angular 
Typescript :: typeorm configuration typescript 
Typescript :: nuxt3 nuxtServerInit 
Typescript :: class in typescript 
Typescript :: datasets in python github 
Typescript :: Header missing on reports odoo 
Typescript :: typescript ingerit 
Typescript :: get keys of an array angualr 
Typescript :: useappdispatch 
Typescript :: Let say your Project Manager tell you that your database requests are consume a lot of memory, you need to do something to improve the performance. How would you do it in hibernate ? 
Typescript :: how to make a class that inherits from another file class in python 
Typescript :: if you meant to render a collection of children use an array instead 
Typescript :: does pure water contain natturaly occuring minerals? 
Typescript :: typescript abstract static method 
Typescript :: typescript override 
Typescript :: some of elements are arrays in python 
Typescript :: how to pass data between requests in api 
Typescript :: how to open and close ports linix 
Typescript :: how to put typescript on continuous build on save 
Typescript :: how were sonnets used in rennaisance litireture 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =