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

Contextual type of methods only in noImplicitAny or JS #50542

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sandersn
Copy link
Member

Fixes #23911, maybe

@sandersn
Copy link
Member Author

@typescript-bot run dt
@typescript-bot user test this
@typescript-bot run rwc

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @sandersn, I've started to run the parallelized Definitely Typed test suite on this PR at 04c2fbd. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @sandersn, I've started to run the diff-based user code test suite on this PR at 04c2fbd. You can monitor the build here.

Update: The results are in!

@sandersn
Copy link
Member Author

@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2022

Heya @sandersn, I've started to run the extended test suite on this PR at 04c2fbd. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@sandersn Here are the results of running the user test suite comparing main and refs/pull/50542/merge:

Something interesting changed - please have a look.

Details

webpack

tsconfig.json

tsconfig.types.json

@typescript-bot
Copy link
Collaborator

Heya @sandersn, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@sandersn sandersn changed the title Contextual type of methods only in noImplicitAny or JSDoc Contextual type of methods only in noImplicitAny or JS Aug 30, 2022
@sandersn
Copy link
Member Author

User tests show a difference only in webpack, which uses checkJS -- there are two new errors where a parameter now inherits the base type but assumes a derived type. And there are many removed noImplicitAny errors.

The RWC diff is empty. I hope that means there are no diffs. But I don't know how many RWC projects have noImplicitAny turned on.

@@ -9134,6 +9134,26 @@ namespace ts {
if (type) {
return addOptionality(type, /*isProperty*/ false, isOptional);
}
if (isMethodDeclaration(func) && isClassLike(func.parent)
&& (noImplicitAny || isInJSFile(func.parent))) { // TODO: Might want to fiddle with restrictions here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity - what's the reasoning to only apply this logic with noImplicitAny (and in JS files)? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. noImplicitAny: untyped parameters will get an error at the same time they get any, so this change can't cause code with 0 errors to compile with >0 errors.
  2. JS files: in JS, errors aren't reported anyway, so any improvement in typing should show up as improvement in completions. (this might need to change to exclude checkjs)

@RyanCavanaugh
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 31, 2022

Heya @RyanCavanaugh, I've started to run the tarball bundle task on this PR at 04c2fbd. You can monitor the build here.

@sandersn
Copy link
Member Author

@typescript-bot test top100

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 31, 2022

Heya @sandersn, I've started to run the diff-based user code test suite on this PR at 04c2fbd. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@sandersn Here are the results of running the top-repos suite comparing main and refs/pull/50542/merge:

Everything looks good!

@somebee
Copy link

somebee commented Sep 27, 2022

This would be fantastic. Hope it gets merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experiment with always using parameters from base types for derived methods
5 participants