-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix completions of optional properties in generic positions #33937
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
Merged
Changes from 16 commits
Commits
Show all changes
18 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 0b46fe3
Don’t change type during inference
andrewbranch 66d8c27
Fix typos and superfluous undefined arguments
andrewbranch c95f6ab
Add test for completions in unconstrained generic object literal
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; | ||
andrewbranch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//// 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' | ||
}, | ||
] | ||
}) |
22 changes: 22 additions & 0 deletions
22
tests/cases/fourslash/completionsWithOptionalPropertiesGenericPartial2.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,22 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @strict: true | ||
|
||
//// interface Foo { | ||
//// a: boolean; | ||
//// } | ||
//// function partialFoo<T extends Partial<Foo>>(x: T, y: T) {return t} | ||
//// partialFoo({ a: true, b: true }, { /*1*/ }); | ||
|
||
verify.completions({ | ||
marker: '1', | ||
includes: [ | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'a' | ||
}, | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'b' | ||
} | ||
] | ||
}) |
29 changes: 29 additions & 0 deletions
29
tests/cases/fourslash/completionsWithOptionalPropertiesGenericPartial3.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,29 @@ | ||
/// <reference path="fourslash.ts" /> | ||
// @strict: true | ||
|
||
////interface Foo { | ||
//// a: boolean; | ||
////} | ||
////function partialFoo<T extends Partial<Foo>>(x: T, y: T extends { b?: boolean } ? T & { c: true } : T) { | ||
//// return x; | ||
////} | ||
//// | ||
////partialFoo({ a: true, b: true }, { /*1*/ }); | ||
|
||
|
||
verify.completions({ | ||
marker: '1', | ||
includes: [ | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'a' | ||
}, | ||
{ | ||
sortText: completion.SortText.OptionalMember, | ||
name: 'b' | ||
}, | ||
{ | ||
name: 'c' | ||
} | ||
] | ||
}) |
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.
Uh oh!
There was an error while loading. Please reload this page.