Consider as const expressions as potentially context sensitive#62221
Open
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Open
Consider as const expressions as potentially context sensitive#62221Andarist wants to merge 1 commit intomicrosoft:mainfrom
as const expressions as potentially context sensitive#62221Andarist wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes TypeScript issue #62220 by making as const expressions context sensitive during type inference. The change allows the TypeScript compiler to properly infer types when as const is used in function arguments that depend on intra-expression type relationships.
Key changes:
- Modified the
isContextSensitivefunction in the type checker to consideras constexpressions as potentially context sensitive - Added comprehensive test cases demonstrating the improved type inference behavior
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/compiler/checker.ts | Core logic change to treat as const expressions as context sensitive when applied to context sensitive expressions |
| tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts | Test cases showing improved type inference with as const expressions |
| tests/baselines/reference/intraExpressionInferences.types | Updated type baselines showing more precise type inference (100 vs number) |
| tests/baselines/reference/intraExpressionInferences.symbols | Updated symbol baselines reflecting the new test cases |
| tests/baselines/reference/intraExpressionInferences.js | Updated JavaScript output baselines |
| tests/baselines/reference/intraExpressionInferences.errors.txt | Updated error baselines with new test content |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #62220