-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix resolution of properties from prototype assignment in JS #29302
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
Changes from all commits
257812c
a9c8dc0
aba1f91
986aaa7
e1f786b
ecb0bec
6cec484
3c137c9
4ead3ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,19 @@ const a = {}; | |
>{} : {} | ||
|
||
a.d = function() {}; | ||
>a.d = function() {} : { (): void; prototype: {}; } | ||
>a.d : { (): void; prototype: {}; } | ||
>a.d = function() {} : typeof d | ||
>a.d : typeof d | ||
>a : typeof a | ||
>d : { (): void; prototype: {}; } | ||
>function() {} : { (): void; prototype: {}; } | ||
>d : typeof d | ||
>function() {} : typeof d | ||
|
||
=== tests/cases/conformance/salsa/b.js === | ||
a.d.prototype = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting...the change in type display indicates that we're now treating (we print the type of 'a' as 'typeof a' because the expando assignments turn it into a namespace.) |
||
>a.d.prototype = {} : {} | ||
>a.d.prototype : {} | ||
>a.d : { (): void; prototype: {}; } | ||
>a.d : typeof d | ||
>a : typeof a | ||
>d : { (): void; prototype: {}; } | ||
>d : typeof d | ||
>prototype : {} | ||
>{} : {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
tests/cases/conformance/salsa/bug26885.js(2,5): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. | ||
tests/cases/conformance/salsa/bug26885.js(11,16): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. | ||
|
||
|
||
==== tests/cases/conformance/salsa/bug26885.js (2 errors) ==== | ||
function Multimap3() { | ||
this._map = {}; | ||
~~~~ | ||
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. | ||
}; | ||
|
||
Multimap3.prototype = { | ||
/** | ||
* @param {string} key | ||
* @returns {number} the value ok | ||
*/ | ||
get(key) { | ||
return this._map[key + '']; | ||
~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. | ||
} | ||
} | ||
|
||
/** @type {Multimap3} */ | ||
const map = new Multimap3(); | ||
const n = map.get('hi') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
=== tests/cases/conformance/salsa/bug26885.js === | ||
function Multimap3() { | ||
>Multimap3 : Symbol(Multimap3, Decl(bug26885.js, 0, 0), Decl(bug26885.js, 2, 2)) | ||
|
||
this._map = {}; | ||
>_map : Symbol(Multimap3._map, Decl(bug26885.js, 0, 22)) | ||
|
||
}; | ||
|
||
Multimap3.prototype = { | ||
>Multimap3.prototype : Symbol(Multimap3.prototype, Decl(bug26885.js, 2, 2)) | ||
>Multimap3 : Symbol(Multimap3, Decl(bug26885.js, 0, 0), Decl(bug26885.js, 2, 2)) | ||
>prototype : Symbol(Multimap3.prototype, Decl(bug26885.js, 2, 2)) | ||
|
||
/** | ||
* @param {string} key | ||
* @returns {number} the value ok | ||
*/ | ||
get(key) { | ||
>get : Symbol(get, Decl(bug26885.js, 4, 23)) | ||
>key : Symbol(key, Decl(bug26885.js, 9, 8)) | ||
|
||
return this._map[key + '']; | ||
>this._map : Symbol(Multimap3._map, Decl(bug26885.js, 0, 22)) | ||
>_map : Symbol(Multimap3._map, Decl(bug26885.js, 0, 22)) | ||
>key : Symbol(key, Decl(bug26885.js, 9, 8)) | ||
} | ||
} | ||
|
||
/** @type {Multimap3} */ | ||
const map = new Multimap3(); | ||
>map : Symbol(map, Decl(bug26885.js, 15, 5)) | ||
>Multimap3 : Symbol(Multimap3, Decl(bug26885.js, 0, 0), Decl(bug26885.js, 2, 2)) | ||
|
||
const n = map.get('hi') | ||
>n : Symbol(n, Decl(bug26885.js, 16, 5)) | ||
>map.get : Symbol(get, Decl(bug26885.js, 4, 23)) | ||
>map : Symbol(map, Decl(bug26885.js, 15, 5)) | ||
>get : Symbol(get, Decl(bug26885.js, 4, 23)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
=== tests/cases/conformance/salsa/bug26885.js === | ||
function Multimap3() { | ||
>Multimap3 : typeof Multimap3 | ||
|
||
this._map = {}; | ||
>this._map = {} : {} | ||
>this._map : any | ||
>this : any | ||
>_map : any | ||
>{} : {} | ||
|
||
}; | ||
|
||
Multimap3.prototype = { | ||
>Multimap3.prototype = { /** * @param {string} key * @returns {number} the value ok */ get(key) { return this._map[key + '']; }} : { get(key: string): number; } | ||
>Multimap3.prototype : { get(key: string): number; } | ||
>Multimap3 : typeof Multimap3 | ||
>prototype : { get(key: string): number; } | ||
>{ /** * @param {string} key * @returns {number} the value ok */ get(key) { return this._map[key + '']; }} : { get(key: string): number; } | ||
|
||
/** | ||
* @param {string} key | ||
* @returns {number} the value ok | ||
*/ | ||
get(key) { | ||
>get : (key: string) => number | ||
>key : string | ||
|
||
return this._map[key + '']; | ||
>this._map[key + ''] : any | ||
>this._map : {} | ||
>this : Multimap3 & { get(key: string): number; } | ||
>_map : {} | ||
>key + '' : string | ||
>key : string | ||
>'' : "" | ||
} | ||
} | ||
|
||
/** @type {Multimap3} */ | ||
const map = new Multimap3(); | ||
>map : Multimap3 & { get(key: string): number; } | ||
>new Multimap3() : Multimap3 & { get(key: string): number; } | ||
>Multimap3 : typeof Multimap3 | ||
|
||
const n = map.get('hi') | ||
>n : number | ||
>map.get('hi') : number | ||
>map.get : (key: string) => number | ||
>map : Multimap3 & { get(key: string): number; } | ||
>get : (key: string) => number | ||
>'hi' : "hi" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
tests/cases/conformance/jsdoc/bug27346.js(2,4): error TS8030: The type of a function declaration must match the function's signature. | ||
tests/cases/conformance/jsdoc/bug27346.js(2,11): error TS2587: JSDoc type 'MyClass' circularly references itself. | ||
|
||
|
||
==== tests/cases/conformance/jsdoc/bug27346.js (2 errors) ==== | ||
==== tests/cases/conformance/jsdoc/bug27346.js (1 errors) ==== | ||
/** | ||
* @type {MyClass} | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS8030: The type of a function declaration must match the function's signature. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the second error goes away because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it might be worthwhile to check whether we have any other error baselines that include the "JSDoc type circularly references itself". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No other baselines had this error, and the original repro from the #27346 doesn't give this error anymore. I removed the circularity guard and no baselines changed, so I'll take that as part of this change too. |
||
~~~~~~~ | ||
!!! error TS2587: JSDoc type 'MyClass' circularly references itself. | ||
*/ | ||
function MyClass() { } | ||
MyClass.prototype = {}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @noEmit: true | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @Filename: bug26885.js | ||
// @strict: true | ||
|
||
function Multimap3() { | ||
this._map = {}; | ||
}; | ||
|
||
Multimap3.prototype = { | ||
/** | ||
* @param {string} key | ||
* @returns {number} the value ok | ||
*/ | ||
get(key) { | ||
return this._map[key + '']; | ||
} | ||
} | ||
|
||
/** @type {Multimap3} */ | ||
const map = new Multimap3(); | ||
const n = map.get('hi') |
Uh oh!
There was an error while loading. Please reload this page.