--noImplicitAny codefixes infer anonymous object types despite appropriate primitives #29321
Labels
Domain: Quick Fixes
Editor-provided fixes, often called code actions.
Experience Enhancement
Noncontroversial enhancements
Suggestion
An idea for TypeScript
Milestone
TypeScript Version: 3.3.0-dev.20190108
Search Terms: noimplicitany infer code fix codefix quick suggested object literal primitive
Code
Expected behavior:
--noImplicitAny
suggested fix on thetext
parameter:Actual behavior:
Related Issues: #13243 (parent tracking quick fixes); #28991 for similar issues with interfaces/types
At what point can TypeScript be confident something is a string, number, array, etc.? In the above case of a parameter whose usages match up to exactly one built-in primitive (
string
here), can it be inferred to that primitive instead of a very long anonymous object type that happens to be a subset of the primitive's?Proposal: If a
--noImplicitAny
fix would add in an anonymous object type that is a subset of exactly one built-in primitive type, such asnumber
,string
, orboolean
, it should add that primitive type instead.The text was updated successfully, but these errors were encountered: