3 ms·
I agree that functions should probably specify their output type, MOSTLY to enforce that all paths that return from that function must adhere to that type I've
by bluefirebrand 2y ago
I agree that functions should probably specify their output type, MOSTLY to enforce that all paths that return from that function must adhere to that type
I've seen plenty of regressions where someone added a new condition to a function and then returned a slightly different type than other branches did, and it broke things
However, I don't think there is much value in putting types on variable declarations
In your example,
`const checkedDoggos = checkDogs([])` is good. Just let checkedDoggos inherit the type from the function
I have a codebase I'm working on where the linter enforces
`const checkedDoggos: DogBreedAndSize[] = checkDogs([])`
It is very silly and doesn't add much value imo
- CharlieDigital 2y agoI want it on the other side (on the function return) so that it's consistently displayed in type hints and intellisense so I don't have to navigate the code backwards 3-4 layers to find the root type (do you see what I'm saying?) function checkDogs(dogs: Dog[]) : DogBreedAndSize[] { return dogs.map(d => /* ... */) } ^^^ That's where it's important to not skip the type def because then I can see the root type in the editor hints and I don't need to dig into the call stack (I know the end result is the same whether it's on the assignment side or the declaration side, but it feels like ensuring it's always on the declaration side is where the value is)