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

Fix #31155 - Remove assignability cases in getNarrowedType #32443

Closed

Conversation

jack-williams
Copy link
Collaborator

@jack-williams jack-williams commented Jul 17, 2019

Fixes #31155

/cc @orta @weswigham

}
s; // Set<number>
>s : Set<number>
>s : Set<number> & Set<any>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these cases where TS would widen to be an any instead of the original number, this feels like something we don't want

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, when accessing the parametrising type you'll end up getting number & any which is going to swallow number - this is definitely a bad change. The problem is that before it was relying on the assignability check to strip out the any case, but now we don't have that.

I think I remember that there was a similar issue that came up in conditional type simplification, where T extends Foo<any> ? A : B was simplified to T & Foo<any>, causing similar problems. @weswigham what was the solution here?

@jack-williams
Copy link
Collaborator Author

This would probably benefit from #30161.

@jack-williams
Copy link
Collaborator Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 18, 2019

Heya @jack-williams, I've started to run the parallelized Definitely Typed test suite on this PR at b6026c2. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 18, 2019

Heya @jack-williams, I've started to run the extended test suite on this PR at b6026c2. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 18, 2019

Heya @jack-williams, I've started to run the parallelized community code test suite on this PR at b6026c2. You can monitor the build here. It should now contribute to this PR's status checks.

@jack-williams
Copy link
Collaborator Author

I've added an additional subtype check to tame the issues of Interface<any> creeping in because these make the change unacceptable. The current baseline changes seem more reasonable.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

I think this is good - briefly cc @ahejlsberg as this is the kind of change to run by you before we merge, if only so everyone's on the same page so we don't reintroduce a similar bug with a different narrowing in the future~

@orta
Copy link
Contributor

orta commented Oct 23, 2019

Ping @ahejlsberg

@ahejlsberg
Copy link
Member

The old test runs have expired. Running again so I can take a look.

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 24, 2019

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at d91d445. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 24, 2019

Heya @ahejlsberg, I've started to run the extended test suite on this PR at d91d445. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 24, 2019

Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at d91d445. You can monitor the build here. It should now contribute to this PR's status checks.

@weswigham
Copy link
Member

You're gunna need to merge this with master to get good, comparable test runs ❤️

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@jack-williams
Copy link
Collaborator Author

@ahejlsberg, @weswigham: I’ll merge and run those tests later today

@jack-williams
Copy link
Collaborator Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 25, 2019

Heya @jack-williams, I've started to run the extended test suite on this PR at b24dbe6. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 25, 2019

Heya @jack-williams, I've started to run the parallelized Definitely Typed test suite on this PR at b24dbe6. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 25, 2019

Heya @jack-williams, I've started to run the parallelized community code test suite on this PR at b24dbe6. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@jack-williams
Copy link
Collaborator Author

DTS failures look to be import/declaration related. Are these noise?

Not entirely sure how to interpret user test failures.

@ahejlsberg
Copy link
Member

The DT failures are noise. Not sure how to look at the user test failures either.

@weswigham
Copy link
Member

Not sure how to look at the user test failures either.

There're a little fail-y on master right now, so you'd need to diff the PR against the master PR. #34727

@jack-williams
Copy link
Collaborator Author

I think the diffs look clean. Only thing that looks significant is a load of errors in src/language-yaml/printer-yaml.js now removed in master - might be unrelated?

@jack-williams
Copy link
Collaborator Author

@typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 5, 2019

Heya @jack-williams, I've started to run the parallelized community code test suite on this PR at b24dbe6. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@jack-williams
Copy link
Collaborator Author

I think the vscode change looks related to this:

[XX:XX:XX] Error: /vscode/src/vs/base/browser/ui/actionbar/actionbar.ts(625,9): Type '(IAction & any[]) | (readonly IAction[] & any[]) | (IAction | readonly IAction[])[]' is not assignable to type 'readonly IAction[]'.
  Type '(IAction | readonly IAction[])[]' is not assignable to type 'readonly IAction[]'.
    Type 'IAction | readonly IAction[]' is not assignable to type 'IAction'.
      Type 'readonly IAction[]' is missing the following properties from type 'IAction': id, label, tooltip, class, and 4 more.
[XX:XX:XX] Error: /vscode/src/vs/base/browser/ui/actionbar/actionbar.ts(625,9): Type '(IAction & any[]) | (readonly IAction[] & any[]) | (IAction | readonly IAction[])[]' is not assignable to type 'readonly IAction[]'.
[XX:XX:XX] Error: /vscode/src/vs/base/browser/ui/actionbar/actionbar.ts(625,9): Type '(IAction & any[]) | (readonly IAction[] & any[]) | (IAction | readonly IAction[])[]' is not assignable to type 'readonly IAction[]'.
  Type '(IAction | readonly IAction[])[]' is not assignable to type 'readonly IAction[]'.
    Type 'IAction | readonly IAction[]' is not assignable to type 'IAction'.
      Type 'readonly IAction[]' is missing the following properties from type 'IAction': id, label, tooltip, class, and 4 more.
[XX:XX:XX] Error: /vscode/src/vs/base/browser/ui/actionbar/actionbar.ts(625,9): Type '(IAction & any[]) | (readonly IAction[] & any[]) | (IAction | readonly IAction[])[]' is not assignable to type 'readonly IAction[]'

@jack-williams
Copy link
Collaborator Author

jack-williams commented Nov 5, 2019

Minimal repro:

interface IAction {
    x: string;
}

declare const arg: IAction | ReadonlyArray<IAction>;
const x = Array.isArray(arg) ? arg : [arg];

Previously x was any[], now it's (IAction & any[]) | (ReadonlyArray<IAction> & any[]) | ( IAction | ReadonlyArray<IAction>)[]

TLDR: any[] is assignable to IAction | ReadonlyArray<IAction>, but it's not a subtype. The issue here is that readonly arrays are not subtypes of mutable arrays so we end up falling back to the intersection case.

I feel slightly reluctant to make any changes to the solution here for a type-guard that has multiple issues open about improving it; though, I don't think this break is acceptable to push into master. Need to come up with some sort of resolution here, which may be trying to resolve isArray first.

@jack-williams
Copy link
Collaborator Author

I think this is potentially blocked on #17002.

@sandersn sandersn added this to Gallery in Pall Mall Jan 30, 2020
@sandersn sandersn added the For Milestone Bug PRs that fix a bug with a specific milestone label Feb 1, 2020
@sandersn sandersn removed this from Gallery in Pall Mall Mar 2, 2020
@sandersn sandersn added this to Waiting on author in PR Backlog Mar 2, 2020
@sandersn
Copy link
Member

This PR hasn't seen any activity for quite a while, so I'm going to close it to keep the number of open PRs manageable. Feel free to open a fresh PR or continue the discussion here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

'instanceof' changes type outside of 'if' statement
6 participants