GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support completions contextual types in more places · Pull Request #20768 · microsoft/TypeScript

Conversation

@ghost

@ghost Deleted user (ghost) commented Dec 18, 2017 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #20760

Sequel to #20020 that supports completions-specific contextual types on an identifier after a new expression. Moves this code from checker to a wrapper in completions.ts since some of these contextual types don't really make sense outside of completions. (E.g., we contextually type an identifier in const x: T = new iden| as T, whereas a correct contextual type would be { new(): T }.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ghost
ghost requested a review from Armando Aguirre (armanio123) December 18, 2017 22:13
@ghost
ghost force-pushed the getRecommendedCompletions branch 3 times, most recently from a71011d to 374654b Compare December 21, 2017 16:18
Andy Hanson
Support completions contextual types in more places
7526d65
@ghost
ghost force-pushed the getRecommendedCompletions branch from 374654b to 7526d65 Compare January 3, 2018 17:11
sandersn
Nathan Shively-Sanders (sandersn) requested changes Jan 3, 2018
View reviewed changes

@sandersn Nathan Shively-Sanders (sandersn) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Seems fine except that I don't understand why removing the contextual typing from === and others doesn't change anything in the batch compilation tests. Can you explain?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/checker.ts
// the contextual type of an initializer expression is the type annotation of the containing declaration, if present.
function getContextualTypeForInitializerExpression(node: Expression): Type {
const declaration = <VariableLikeDeclaration>node.parent;
if (hasInitializer(declaration) && node === declaration.initializer || node.kind === SyntaxKind.EqualsToken) {

@sandersn Nathan Shively-Sanders (sandersn) Jan 3, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why does = go away? I guess that it's because in batch compilation, = doesn't have a type, and node is in fact only ever = when called from services.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ghost Deleted user (ghost) Jan 3, 2018

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Right, this code was added in #20020 and this PR moves the special cases to completions.ts.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/checker.ts
case SyntaxKind.ExclamationEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
// For completions after `x === `
return node === operatorToken ? getTypeOfExpression(binaryExpression.left) : undefined;

@sandersn Nathan Shively-Sanders (sandersn) Jan 3, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

is this really not used anywhere else besides services?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ghost Deleted user (ghost) Jan 3, 2018

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, this was also added by #20020.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/services/completions.ts Outdated
case ts.SyntaxKind.EqualsToken:
return ts.isVariableDeclaration(parent)
? checker.getContextualType(parent.initializer)
: ts.isBinaryExpression(parent)

@sandersn Nathan Shively-Sanders (sandersn) Jan 3, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

can you reformat like so?

return ts.isVariableDeclaration(parent) ? checker.getContextualType(parent.initializer) :
    ts.isBinaryExpression(parent) ? checker.getTypeAtLocation(parent.left) : undefined;

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Andy Hanson
Adjust formatting
60b06a3
sandersn
Nathan Shively-Sanders (sandersn) approved these changes Jan 3, 2018
View reviewed changes
@ghost
ghost merged commit a33f229 into master Jan 3, 2018
@ghost
ghost deleted the getRecommendedCompletions branch January 3, 2018 21:51
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jul 3, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@armanio123 Armando Aguirre (armanio123) Awaiting requested review from armanio123

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@sandersn
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.