With TypeScript, you can explicitly specify types or let the compiler output them.
Is there a way to add types that are output to the source code?
For example, I would start with:
private posX = 0;
private posY = 0;
private sizeX = 0;
private sizeY = 0;
I would do type inference, and since types can be inferred in this case, I would get:
private posX: number = 0;
private posY: number = 0;
private sizeX: number = 0;
private sizeY: number = 0;
That way, when editing the code, I can check if the output worked as I expect, and I could manually provide more restrictive types if necessary.
source
share