4

With TypeScript you can either specify types explicitly or let the compiler infer them.

Is there a way to add the types that are inferred to the original source code?

Eg I would start with:

private posX = 0;
private posY = 0;
private sizeX = 0;
private sizeY = 0;

I would run type inference, and since the types can be inferred in that case I would get:

private posX: number = 0;
private posY: number = 0;
private sizeX: number = 0;
private sizeY: number = 0;

This way when editing the code I could check if the inference worked as I expect, and I could manually provide more restrictive types if appropriate.

MasterScrat
  • 7,090
  • 14
  • 48
  • 80
  • 2
    I'm not sure if such a library exists or not, but you can probably do that using the [compiler api](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API). – Nitzan Tomer Aug 16 '17 at 08:07
  • @NitzanTomer yes this is definitely possible. But I don't want to reinvent the wheel if there's already a tool to do it ;-) – MasterScrat Aug 16 '17 at 08:11
  • 2
    And I don't blame you. But, this isn't the place to ask such a question. – Nitzan Tomer Aug 16 '17 at 08:15

1 Answers1

2

Someone actually implemented this!

https://github.com/urish/typewiz

MasterScrat
  • 7,090
  • 14
  • 48
  • 80