Skip to content

Resolve keyof and index operations instead of their targets. #58758

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

Merged

Conversation

dragomirtitian
Copy link
Contributor

Fixes #58752

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 3, 2024
@@ -11644,6 +11644,14 @@ export function unwrapParenthesizedExpression(o: Expression) {
return o;
}

/** @internal */
export function unwrapParenthesizedType(o: TypeNode) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised we don't already have this helper...

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 was surprised too. But I could not find it if it exists. There is one that walks up.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it's skipTypeParentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Didn't think to look for that. I'll fix it tomorrow.

Comment on lines 8626 to 8656
function tryVisitIndexAccess(node: IndexedAccessTypeNode): TypeNode | undefined {
const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
if (resultObjectType === undefined) {
return undefined;
}
return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode)!);
}
function tryVisitKeyOf(node: TypeOperatorNode): TypeNode | undefined {
Debug.assertEqual(node.operator, SyntaxKind.KeyOfKeyword);
const type = tryVisitSimpleTypeNode(node.type);
if (type === undefined) {
return undefined;
}
return factory.updateTypeOperatorNode(node, type);
}
function tryVisitTypeQuery(node: TypeQueryNode): TypeNode | undefined {
const { introducesError, node: exprName } = trackExistingEntityName(node.exprName, context);
if (!introducesError) {
return factory.updateTypeQueryNode(
node,
exprName,
visitNodes(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
);
}

const serializedName = serializeTypeName(context, node.exprName, /*isTypeOf*/ true);
if (serializedName) {
return setTextRange(context, serializedName, node.exprName);
}
}
function tryVisitTypeReference(node: TypeReferenceNode): TypeNode | undefined {
Copy link
Member

@DanielRosenwasser DanielRosenwasser Jun 3, 2024

Choose a reason for hiding this comment

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

Suggested change
function tryVisitIndexAccess(node: IndexedAccessTypeNode): TypeNode | undefined {
const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
if (resultObjectType === undefined) {
return undefined;
}
return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode)!);
}
function tryVisitKeyOf(node: TypeOperatorNode): TypeNode | undefined {
Debug.assertEqual(node.operator, SyntaxKind.KeyOfKeyword);
const type = tryVisitSimpleTypeNode(node.type);
if (type === undefined) {
return undefined;
}
return factory.updateTypeOperatorNode(node, type);
}
function tryVisitTypeQuery(node: TypeQueryNode): TypeNode | undefined {
const { introducesError, node: exprName } = trackExistingEntityName(node.exprName, context);
if (!introducesError) {
return factory.updateTypeQueryNode(
node,
exprName,
visitNodes(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
);
}
const serializedName = serializeTypeName(context, node.exprName, /*isTypeOf*/ true);
if (serializedName) {
return setTextRange(context, serializedName, node.exprName);
}
}
function tryVisitTypeReference(node: TypeReferenceNode): TypeNode | undefined {
function tryVisitIndexAccess(node: IndexedAccessTypeNode): TypeNode | undefined {
const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
if (resultObjectType === undefined) {
return undefined;
}
return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode)!);
}
function tryVisitKeyOf(node: TypeOperatorNode): TypeNode | undefined {
Debug.assertEqual(node.operator, SyntaxKind.KeyOfKeyword);
const type = tryVisitSimpleTypeNode(node.type);
if (type === undefined) {
return undefined;
}
return factory.updateTypeOperatorNode(node, type);
}
function tryVisitTypeQuery(node: TypeQueryNode): TypeNode | undefined {
const { introducesError, node: exprName } = trackExistingEntityName(node.exprName, context);
if (!introducesError) {
return factory.updateTypeQueryNode(
node,
exprName,
visitNodes(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
);
}
const serializedName = serializeTypeName(context, node.exprName, /*isTypeOf*/ true);
if (serializedName) {
return setTextRange(context, serializedName, node.exprName);
}
}
function tryVisitTypeReference(node: TypeReferenceNode): TypeNode | undefined {

Copy link
Member

Choose a reason for hiding this comment

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

It's just newlines between the declarations

}
return visitNode(node, visitExistingNodeTreeSymbols, isTypeNode);
}
function tryVisitIndexAccess(node: IndexedAccessTypeNode): TypeNode | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

tryVisitIndexedAccess

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 3, 2024

Seems reasonable. Can you just address the style nits? I don't have edit access.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jun 3, 2024
@DanielRosenwasser
Copy link
Member

@typescript-bot cherry-pick to release-5.5

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 3, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
cherry-pick to release-5.5 ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

Hey, @DanielRosenwasser! I've created #58767 for you.

@DanielRosenwasser DanielRosenwasser merged commit 3702283 into microsoft:main Jun 3, 2024
DanielRosenwasser added a commit that referenced this pull request Jun 3, 2024
…e-5.5 (#58767)

Co-authored-by: Titian Cernicova-Dragomir <[email protected]>
Co-authored-by: Daniel Rosenwasser <[email protected]>
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
None yet
Development

Successfully merging this pull request may close these issues.

[ts-5.5]Some types are excessively expanded in keyof and index access types
4 participants