-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
TypeScript Version: 3.3.0-dev.20181212
Search Terms: noimplicitany infer code fix codefix quick suggested
Code
interface IBox {
x: number;
y: number;
}
const shiftBox = (box) => {
box.x += 1;
box.y += 1;
}
const box = {
x: 0,
y: 0,
};
shiftBox(box);Expected behavior:
--noImplicitAny suggested fix on the box parameter:
const shiftBox = (box: IBox) =>Actual behavior:
const shiftBox = (box: { x: any; y: any; }) => {Related Issues: #13243 (parent tracking quick fixes) and #15114 (discussion on inference difficulties)
If there is an interface available that can satisfy an inferred type in a --noImplicitAny code fix, can we use that? Perhaps with an ordering of possibilities like:
- Interfaces already available in the file, by how small they are
- User-defined interfaces that could be imported, by how distant the file is
- Module types already imported in a user file, by how distant the nearest import is
...where, if multiple interfaces could satisfy the best possibility of those three, we choose the one with the fewest fields?
In code bases that don't explicitly type when unnecessary (e.g. : IBox for variables), I'm finding the --noImplicitAny fixes to be a bit useless for anything other than primitives.