Search code examples
typescripttype-inferencetooling

Add the types inferred by the TypeScript compiler to the original TS source code


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.


Solution

  • Someone actually implemented this!

    https://github.com/urish/typewiz