-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Use proper type parameter hosts in JS files #61013
Open
Andarist
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
Andarist:fix/implementation-signature-context-jsdoc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd6e8f7
Use better context scope for class constructor implementation signatu…
Andarist 378786d
reuse the new function
Andarist b352c0f
remove unused import
Andarist 230925a
add test
Andarist 3107e11
Reuse `getEffectiveTypeParameterHost` in `isTypeParameterPossiblyRefe…
Andarist 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 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
70 changes: 70 additions & 0 deletions
70
tests/baselines/reference/inferFromReturnOfContextSensitiveFnJsDoc1.symbols
This file contains 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,70 @@ | ||
//// [tests/cases/compiler/inferFromReturnOfContextSensitiveFnJsDoc1.ts] //// | ||
|
||
=== index.js === | ||
/** | ||
* @template S | ||
* @param {(arg0: { observer: EO }) => S} callback | ||
* @param {Options} [options] | ||
* @returns {VC<S>} | ||
*/ | ||
/* | ||
* @type { <S>(fn: (arg0: { observer: EO; }) => S, options?: Options) => VC<S> } | ||
*/ | ||
function define(callback, options) { | ||
>define : Symbol(define, Decl(index.js, 0, 0)) | ||
>callback : Symbol(callback, Decl(index.js, 9, 16)) | ||
>options : Symbol(options, Decl(index.js, 9, 25)) | ||
|
||
const { name } = options ?? {}; | ||
>name : Symbol(name, Decl(index.js, 10, 9)) | ||
>options : Symbol(options, Decl(index.js, 9, 25)) | ||
|
||
const observer = new EO(); | ||
>observer : Symbol(observer, Decl(index.js, 11, 7)) | ||
>EO : Symbol(EO, Decl(index.js, 28, 1)) | ||
|
||
const state = callback({ observer }); | ||
>state : Symbol(state, Decl(index.js, 12, 7)) | ||
>callback : Symbol(callback, Decl(index.js, 9, 16)) | ||
>observer : Symbol(observer, Decl(index.js, 12, 26)) | ||
|
||
return new VC(state); | ||
>VC : Symbol(VC, Decl(index.js, 14, 1)) | ||
>state : Symbol(state, Decl(index.js, 12, 7)) | ||
} | ||
|
||
/** | ||
* @template S | ||
*/ | ||
class VC { | ||
>VC : Symbol(VC, Decl(index.js, 14, 1)) | ||
|
||
/** @type {S} */ | ||
state; | ||
>state : Symbol(VC.state, Decl(index.js, 19, 10)) | ||
|
||
/** | ||
* @param {S} state | ||
*/ | ||
constructor(state) { | ||
>state : Symbol(state, Decl(index.js, 25, 14)) | ||
|
||
this.state = state; | ||
>this.state : Symbol(VC.state, Decl(index.js, 19, 10)) | ||
>this : Symbol(VC, Decl(index.js, 14, 1)) | ||
>state : Symbol(VC.state, Decl(index.js, 19, 10)) | ||
>state : Symbol(state, Decl(index.js, 25, 14)) | ||
} | ||
} | ||
|
||
/** @typedef {{ name?: string }} Options */ | ||
|
||
class EO {} | ||
>EO : Symbol(EO, Decl(index.js, 28, 1)) | ||
|
||
const v1 = define((arg0) => true, { name: "default" }); | ||
>v1 : Symbol(v1, Decl(index.js, 34, 5)) | ||
>define : Symbol(define, Decl(index.js, 0, 0)) | ||
>arg0 : Symbol(arg0, Decl(index.js, 34, 19)) | ||
>name : Symbol(name, Decl(index.js, 34, 35)) | ||
|
118 changes: 118 additions & 0 deletions
118
tests/baselines/reference/inferFromReturnOfContextSensitiveFnJsDoc1.types
This file contains 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,118 @@ | ||
//// [tests/cases/compiler/inferFromReturnOfContextSensitiveFnJsDoc1.ts] //// | ||
|
||
=== index.js === | ||
/** | ||
* @template S | ||
* @param {(arg0: { observer: EO }) => S} callback | ||
* @param {Options} [options] | ||
* @returns {VC<S>} | ||
*/ | ||
/* | ||
* @type { <S>(fn: (arg0: { observer: EO; }) => S, options?: Options) => VC<S> } | ||
*/ | ||
function define(callback, options) { | ||
>define : <S>(callback: (arg0: { observer: EO; }) => S, options?: Options) => VC<S> | ||
> : ^ ^^ ^^ ^^ ^^^ ^^^^^ | ||
>callback : (arg0: { observer: EO; }) => S | ||
> : ^ ^^ ^^^^^ | ||
>options : Options | undefined | ||
> : ^^^^^^^^^^^^^^^^^^^ | ||
|
||
const { name } = options ?? {}; | ||
>name : string | undefined | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
>options ?? {} : Options | ||
> : ^^^^^^^ | ||
>options : Options | undefined | ||
> : ^^^^^^^^^^^^^^^^^^^ | ||
>{} : {} | ||
> : ^^ | ||
|
||
const observer = new EO(); | ||
>observer : EO | ||
> : ^^ | ||
>new EO() : EO | ||
> : ^^ | ||
>EO : typeof EO | ||
> : ^^^^^^^^^ | ||
|
||
const state = callback({ observer }); | ||
>state : S | ||
> : ^ | ||
>callback({ observer }) : S | ||
> : ^ | ||
>callback : (arg0: { observer: EO; }) => S | ||
> : ^ ^^ ^^^^^ | ||
>{ observer } : { observer: EO; } | ||
> : ^^^^^^^^^^^^^^^^^ | ||
>observer : EO | ||
> : ^^ | ||
|
||
return new VC(state); | ||
>new VC(state) : VC<S> | ||
> : ^^^^^ | ||
>VC : typeof VC | ||
> : ^^^^^^^^^ | ||
>state : S | ||
> : ^ | ||
} | ||
|
||
/** | ||
* @template S | ||
*/ | ||
class VC { | ||
>VC : VC<S> | ||
> : ^^^^^ | ||
|
||
/** @type {S} */ | ||
state; | ||
>state : S | ||
> : ^ | ||
|
||
/** | ||
* @param {S} state | ||
*/ | ||
constructor(state) { | ||
>state : S | ||
> : ^ | ||
|
||
this.state = state; | ||
>this.state = state : S | ||
> : ^ | ||
>this.state : S | ||
> : ^ | ||
>this : this | ||
> : ^^^^ | ||
>state : S | ||
> : ^ | ||
>state : S | ||
> : ^ | ||
} | ||
} | ||
|
||
/** @typedef {{ name?: string }} Options */ | ||
|
||
class EO {} | ||
>EO : EO | ||
> : ^^ | ||
|
||
const v1 = define((arg0) => true, { name: "default" }); | ||
>v1 : VC<boolean> | ||
> : ^^^^^^^^^^^ | ||
>define((arg0) => true, { name: "default" }) : VC<boolean> | ||
> : ^^^^^^^^^^^ | ||
>define : <S>(callback: (arg0: { observer: EO; }) => S, options?: Options) => VC<S> | ||
> : ^ ^^ ^^ ^^ ^^^ ^^^^^ | ||
>(arg0) => true : (arg0: { observer: EO; }) => boolean | ||
> : ^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ | ||
>arg0 : { observer: EO; } | ||
> : ^^^^^^^^^^^^ ^^^ | ||
>true : true | ||
> : ^^^^ | ||
>{ name: "default" } : { name: string; } | ||
> : ^^^^^^^^^^^^^^^^^ | ||
>name : string | ||
> : ^^^^^^ | ||
>"default" : "default" | ||
> : ^^^^^^^^^ | ||
|
57 changes: 57 additions & 0 deletions
57
...aselines/reference/inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.symbols
This file contains 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,57 @@ | ||
//// [tests/cases/compiler/inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts] //// | ||
|
||
=== inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts === | ||
class S<T> { | ||
>S : Symbol(S, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 0)) | ||
>T : Symbol(T, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 8)) | ||
|
||
set: Set<T>; | ||
>set : Symbol(S.set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 12)) | ||
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) | ||
>T : Symbol(T, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 8)) | ||
|
||
constructor(set: Set<T>) { | ||
>set : Symbol(set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 3, 14)) | ||
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) | ||
>T : Symbol(T, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 8)) | ||
|
||
this.set = set; | ||
>this.set : Symbol(S.set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 12)) | ||
>this : Symbol(S, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 0)) | ||
>set : Symbol(S.set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 12)) | ||
>set : Symbol(set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 3, 14)) | ||
} | ||
|
||
array() { | ||
>array : Symbol(S.array, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 5, 3)) | ||
|
||
return new S(new Set([...this.set].map((item) => [item]))); | ||
>S : Symbol(S, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 0)) | ||
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) | ||
>[...this.set].map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) | ||
>this.set : Symbol(S.set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 12)) | ||
>this : Symbol(S, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 0)) | ||
>set : Symbol(S.set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 12)) | ||
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) | ||
>item : Symbol(item, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 8, 44)) | ||
>item : Symbol(item, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 8, 44)) | ||
} | ||
} | ||
|
||
function sArray<T>(set: Set<T>) { | ||
>sArray : Symbol(sArray, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 10, 1)) | ||
>T : Symbol(T, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 12, 16)) | ||
>set : Symbol(set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 12, 19)) | ||
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) | ||
>T : Symbol(T, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 12, 16)) | ||
|
||
return new S(new Set([...set].map((item) => [item]))); | ||
>S : Symbol(S, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 0, 0)) | ||
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) | ||
>[...set].map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) | ||
>set : Symbol(set, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 12, 19)) | ||
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) | ||
>item : Symbol(item, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 13, 37)) | ||
>item : Symbol(item, Decl(inferenceOuterResultNotIncorrectlyInstantiatedWithInnerResult2.ts, 13, 37)) | ||
} | ||
|
Oops, something went wrong.
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 sort of makes me wonder when we really should be using
getEffectiveJSDocHost
where we are currently usinggetEffectiveContainerForJSDocTemplateTag
...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, but to be fair - I had to use
getEffectiveJSDocHost
to fix this issue at hand and it didn't look to me like this older function would have to stick to the other one. There is a chance that it should not use this - but there is also a chance that this change fixed some other issue ;pIn the ideal world, I'd go through all of the callers to both and assess their needs but I just don't have time to do that right now 😢