Skip to content

Fixed an issue with unsound indexed access on unknown type param #49729

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

Conversation

Andarist
Copy link
Contributor

given the changed behavior from #49119 those indexed accesses within those generic functions should error as mentioned by @RyanCavanaugh here: #49696 (comment)

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 29, 2022
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

!!! error TS2531: Object is possibly 'null'.
}

test(null, 'foo')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've included those calls as there was a temporary regression related to this, you can check out here. I've figured out that this might be worth it to add here as part of the regression tests

@@ -28892,7 +28892,7 @@ namespace ts {
return errorType;
}
const facts = getTypeFacts(type);
if (facts & TypeFacts.IsUndefinedOrNull) {
if (facts & TypeFacts.IsUndefinedOrNull || type.flags & (TypeFlags.Intersection | TypeFlags.Instantiable) && (getBaseConstraintOfType(type) || unknownType) === unknownType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Andarist
Copy link
Contributor Author

I've checked a good chunk of the failures and I think they are all sound - those places should fail. Perhaps some of them could report different errors though or some errors could be skipped for brevity on the assumption that there is another related error reported for the given piece of code.

@Andarist Andarist closed this Jul 7, 2022
@Andarist
Copy link
Contributor Author

Andarist commented Jul 7, 2022

Closed as it turns out that perhaps allowing such indexed access might be desirable: #49696 (comment)

@Andarist Andarist deleted the fix/generic-unknown-type-param-with-keyof-indexed-access branch July 7, 2022 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants