Typescript equivalent decltype in C ++?

decltypein C ++ returns the type of expression, for example it decltype(1+1)will int.

Note that the expression will not be executed or compiled.

Does Typescript have something like this?

An example usecase that I think should work:

const foo = () => ({a: '', b: 0});
type foo_return_type = decltype(foo());
// foo_return_type should be '{a: stirng, b: number}`

import { bar } from './some_module';
type my_type = decltype(new bar().some_method());
+4
source share

Source: https://habr.com/ru/post/1683783/


All Articles