-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixes #30507 #32100
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
Closed
timsuchanek
wants to merge
15
commits into
microsoft:master
from
timsuchanek:genericObjectExpressionCompletion
Closed
Fixes #30507 #32100
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8e37e0a
fixes #30507
timsuchanek 5c561ea
Add test case for generic Partial type
timsuchanek d674ee0
Fixes #28470
timsuchanek ad166f7
Simplify contextFlags binary check
timsuchanek 50286b9
Add string literal completion test
timsuchanek ba1e478
Fix ContextFlags typings
timsuchanek adf8a54
Speed up inference expression for completion
timsuchanek 25fa027
Fix baseline merge
andrewbranch 7883ec6
Make contextFlags internal
timsuchanek 7e7dc08
Reapply readonly array changes
timsuchanek c1a47a5
accept baselines
timsuchanek 96a782e
Fix generic completion tests
timsuchanek 5ae31ff
Merge master
orta b863e01
Merge branch 'master' into genericObjectExpressionCompletion
andrewbranch d1cb5cb
Re-merge ContextFlags
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
11 changes: 11 additions & 0 deletions
11
tests/cases/fourslash/completionsWithGenericStringLiteral.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @strict: true | ||
|
||
//// declare function get<T, K extends keyof T>(obj: T, key: K): T[K]; | ||
//// get({ hello: 123, world: 456 }, "/**/"); | ||
|
||
verify.completions({ | ||
marker: "", | ||
includes: ['hello', 'world'] | ||
}); | ||
|
19 changes: 19 additions & 0 deletions
19
tests/cases/fourslash/completionsWithOptionalPropertiesGeneric.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @strict: true | ||
|
||
//// interface MyOptions { | ||
//// hello?: boolean; | ||
//// world?: boolean; | ||
//// } | ||
//// declare function bar<T extends MyOptions>(options?: Partial<T>): void; | ||
//// bar({ hello, /*1*/ }); | ||
|
||
verify.completions({ | ||
marker: '1', | ||
includes: [ | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'world' | ||
}, | ||
] | ||
}) |
27 changes: 27 additions & 0 deletions
27
tests/cases/fourslash/completionsWithOptionalPropertiesGenericConstructor.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @strict: true | ||
|
||
//// interface Options { | ||
//// someFunction?: () => string | ||
//// anotherFunction?: () => string | ||
//// } | ||
//// | ||
//// export class Clazz<T extends Options> { | ||
//// constructor(public a: T) {} | ||
//// } | ||
//// | ||
//// new Clazz({ /*1*/ }) | ||
|
||
verify.completions({ | ||
marker: '1', | ||
includes: [ | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'someFunction' | ||
}, | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'anotherFunction' | ||
}, | ||
] | ||
}) |
23 changes: 23 additions & 0 deletions
23
tests/cases/fourslash/completionsWithOptionalPropertiesGenericDeep.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @strict: true | ||
|
||
//// interface DeepOptions { | ||
//// another?: boolean; | ||
//// } | ||
//// interface MyOptions { | ||
//// hello?: boolean; | ||
//// world?: boolean; | ||
//// deep?: DeepOptions | ||
//// } | ||
//// declare function bar<T extends MyOptions>(options?: Partial<T>): void; | ||
//// bar({ deep: {/*1*/} }); | ||
|
||
verify.completions({ | ||
marker: '1', | ||
includes: [ | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'another' | ||
}, | ||
] | ||
}) |
33 changes: 33 additions & 0 deletions
33
tests/cases/fourslash/completionsWithOptionalPropertiesGenericPartial.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @strict: true | ||
|
||
//// interface Foo { | ||
//// a_a: boolean; | ||
//// a_b: boolean; | ||
//// a_c: boolean; | ||
//// b_a: boolean; | ||
//// } | ||
//// function partialFoo<T extends Partial<Foo>>(t: T) {return t} | ||
//// partialFoo({ /*1*/ }); | ||
|
||
verify.completions({ | ||
marker: '1', | ||
includes: [ | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'a_a' | ||
}, | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'a_b' | ||
}, | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'a_c' | ||
}, | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'b_a' | ||
}, | ||
] | ||
}) |
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.
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.
This doesn't seem like the right place to do this - rather than passing the flag all the way thru signature resolution, if this flag is set, we should just look at the "base signature" (
getBaseSignature
) rather than starting inference at all, I think. Then again, if we did that we wouldn't get an instantiated constraint which reports more detailed information on circular constraints. Then again again, I'm pretty sure as-is this is caching into theresolvedSignature
of a node, which this very much is not - which means requesting completions poisons the cache with incorrect types for later checking.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.
Thanks for the feedback @weswigham! Do you have a suggestion how we still could fix the autocompletion for this? This was, unfortunately, the only way I found (with my limited knowledge of the codebase).
Maybe introducing a new method as an alternative to
getContextualType
just to be used by the completion service?Uh oh!
There was an error while loading. Please reload this page.
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.
I think
getContextualType
is still right, we just need to avoid using any resolved signature caches.