Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider making implicit any the default for all generic type parameters #13609

Closed
RyanCavanaugh opened this issue Jan 21, 2017 · 10 comments
Closed
Assignees
Labels
Committed The team has roadmapped this issue Suggestion An idea for TypeScript

Comments

@RyanCavanaugh
Copy link
Member

Now that we have generic defaults (:tada:), we should consider making all type parameters have an implicit any default. An unspecified uninferred type parameter would have type any and trigger a warning under noImplicitAny.

Benefits:

  • We'll need to do this in Salsa anyway
  • Improves JS migration story for codebases which inherit from generic base classes

Drawbacks:

  • There may exist people who run with noImplicitAny off but still want to enforce type parameters to be provided?
@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jan 21, 2017
@falsandtru
Copy link
Contributor

trigger a warning under noImplicitAny.

It's a really great improvement.
I definitely want it.

@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue and removed In Discussion Not yet reached consensus labels Jan 24, 2017
@RyanCavanaugh
Copy link
Member Author

@rbuckton interested in folding this into your current PR? We can also do it later instead

@mhegazy
Copy link
Contributor

mhegazy commented Jan 24, 2017

I would keep this in a separate PR.

@gcnew
Copy link
Contributor

gcnew commented Jan 24, 2017

Wouldn't this be at odds with #1213 and #9949?

@DanielRosenwasser
Copy link
Member

@gcnew could you elaborate on that thought?

@gcnew
Copy link
Contributor

gcnew commented Jan 24, 2017

My hunch is that defaulting parameters to an implicit value is not a good idea in general. I don't have anything specific, it was more like throwing in areas where potential issues may reside.

Giving it a second thought, defaulting parameters to any will make the checker more permissive for users with noImplicitAny off. If #1213 and #9949 get implemented, the checker will become more restrictive again, which may be viewed as a backwards compatibility problem. On the other hand this proposal is beneficial for noImplicitAny users.

@DanielRosenwasser
Copy link
Member

@gcnew I don't think that the implicit {} constraint type is much better though. If anything, {} is confusing for newcomers, and the behavior of getting it rather than any is actually more confusing for those who are familiar with noImplicitAny. I do think that the positives you listed are pretty compelling though, and explain much of the rationale for this proposal.

@RyanCavanaugh I just want to clarify the intent - is it all type parameters including those which have explicit defaults?

@RyanCavanaugh
Copy link
Member Author

If there's an explicit default, we would obviously use that instead of any. Maybe I don't understand the question.

@DanielRosenwasser
Copy link
Member

Sorry, I meant to ask about explicit constraints, not explicit defaults.

@RyanCavanaugh
Copy link
Member Author

Somehow decided we should do #10571 as part of this discussion

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Committed The team has roadmapped this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants