Issue
I want to access the type of the value of a returntype of a function.
I can use this code to get the type, but it is not "clean" by any means, since it creates the unused variable ftype to be able to read the values.
const f = () => ({ a: 'a', b: 0 });
let ftype: ReturnType<typeof f>;
let atype: typeof ftype.a;
let btype: typeof ftype.b;
is there a proper way of doing it?
Solution
You can use an indexed access type :
ReturnType<typeof f>['a']; // string
ReturnType<typeof f>['b']; // number
Answered By - Matthieu Riegler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.