Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  91] [ 2]  / answers: 1 / hits: 17979  / 7 Years ago, mon, july 10, 2017, 12:00:00

I'm trying to create a function that returns a Promise with values that can be resolved to null.


Basically something like this:


static getUserById(ids: String): Promise<?User> {
// do something
}

but it is returning an error



Generic type 'Promise' requires 1 type argument(s)



How to create a function in TypeScript that can return a Promise with nullable resolved values?


More From » typescript

 Answers
66

? means optionnal parameter not nullable type.



You should use this:



Promise<User|null>

[#57143] Friday, July 7, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
morrismilom

Total Points: 230
Total Questions: 96
Total Answers: 114

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;