Skip to content

Cache & widen assigned js prototype type #32381

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 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22750,7 +22750,7 @@ namespace ts {
isVariableDeclaration(decl.parent) && getSymbolOfNode(decl.parent));
const prototype = assignmentSymbol && assignmentSymbol.exports && assignmentSymbol.exports.get("prototype" as __String);
const init = prototype && prototype.valueDeclaration && getAssignedJSPrototype(prototype.valueDeclaration);
return init ? checkExpression(init) : undefined;
return init ? getWidenedType(checkExpressionCached(init)) : undefined;
}

function getAssignedJSPrototype(node: Node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
tests/cases/compiler/index.js(1,16): error TS7006: Parameter 'obj' implicitly has an 'any' type.
tests/cases/compiler/index.js(6,21): error TS7006: Parameter 'ratio' implicitly has an 'any' type.
tests/cases/compiler/index.js(7,20): error TS7006: Parameter 'ratio' implicitly has an 'any' type.
tests/cases/compiler/index.js(8,22): error TS7006: Parameter 'ratio' implicitly has an 'any' type.
tests/cases/compiler/index.js(9,24): error TS7006: Parameter 'ratio' implicitly has an 'any' type.
tests/cases/compiler/index.js(10,20): error TS7006: Parameter 'ratio' implicitly has an 'any' type.
tests/cases/compiler/index.js(11,21): error TS7006: Parameter 'ratio' implicitly has an 'any' type.
tests/cases/compiler/index.js(13,21): error TS7006: Parameter 'ratio' implicitly has an 'any' type.
tests/cases/compiler/index.js(14,2): error TS7023: 'toJSON' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
tests/cases/compiler/index.js(14,35): error TS2339: Property 'rgb' does not exist on type 'Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }'.


==== tests/cases/compiler/index.js (10 errors) ====
function Color(obj) {
~~~
!!! error TS7006: Parameter 'obj' implicitly has an 'any' type.
this.example = true
};
Color.prototype = {
negate: function () {return this;},
lighten: function (ratio) {return this;},
~~~~~
!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type.
darken: function (ratio) {return this;},
~~~~~
!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type.
saturate: function (ratio) {return this;},
~~~~~
!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type.
desaturate: function (ratio) {return this;},
~~~~~
!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type.
whiten: function (ratio) {return this;},
~~~~~
!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type.
blacken: function (ratio) {return this;},
~~~~~
!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type.
greyscale: function () {return this;},
clearer: function (ratio) {return this;},
~~~~~
!!! error TS7006: Parameter 'ratio' implicitly has an 'any' type.
toJSON: function () {return this.rgb();},
~~~~~~
!!! error TS7023: 'toJSON' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
~~~
!!! error TS2339: Property 'rgb' does not exist on type 'Color & { negate: () => Color & any; lighten: (ratio: any) => Color & any; darken: (ratio: any) => Color & any; saturate: (ratio: any) => Color & any; desaturate: (ratio: any) => Color & any; whiten: (ratio: any) => Color & any; blacken: (ratio: any) => Color & any; greyscale: () => Color & any; clearer: (ratio: any) => Color & any; toJSON: () => any; }'.
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//// [index.js]
function Color(obj) {
this.example = true
};
Color.prototype = {
negate: function () {return this;},
lighten: function (ratio) {return this;},
darken: function (ratio) {return this;},
saturate: function (ratio) {return this;},
desaturate: function (ratio) {return this;},
whiten: function (ratio) {return this;},
blacken: function (ratio) {return this;},
greyscale: function () {return this;},
clearer: function (ratio) {return this;},
toJSON: function () {return this.rgb();},
};

//// [index.js]
function Color(obj) {
this.example = true;
}
;
Color.prototype = {
negate: function () { return this; },
lighten: function (ratio) { return this; },
darken: function (ratio) { return this; },
saturate: function (ratio) { return this; },
desaturate: function (ratio) { return this; },
whiten: function (ratio) { return this; },
blacken: function (ratio) { return this; },
greyscale: function () { return this; },
clearer: function (ratio) { return this; },
toJSON: function () { return this.rgb(); }
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=== tests/cases/compiler/index.js ===
function Color(obj) {
>Color : Symbol(Color, Decl(index.js, 0, 0), Decl(index.js, 2, 2))
>obj : Symbol(obj, Decl(index.js, 0, 15))

this.example = true
>example : Symbol(Color.example, Decl(index.js, 0, 21))

};
Color.prototype = {
>Color.prototype : Symbol(Color.prototype, Decl(index.js, 2, 2))
>Color : Symbol(Color, Decl(index.js, 0, 0), Decl(index.js, 2, 2))
>prototype : Symbol(Color.prototype, Decl(index.js, 2, 2))

negate: function () {return this;},
>negate : Symbol(negate, Decl(index.js, 3, 19))

lighten: function (ratio) {return this;},
>lighten : Symbol(lighten, Decl(index.js, 4, 36))
>ratio : Symbol(ratio, Decl(index.js, 5, 20))

darken: function (ratio) {return this;},
>darken : Symbol(darken, Decl(index.js, 5, 42))
>ratio : Symbol(ratio, Decl(index.js, 6, 19))

saturate: function (ratio) {return this;},
>saturate : Symbol(saturate, Decl(index.js, 6, 41))
>ratio : Symbol(ratio, Decl(index.js, 7, 21))

desaturate: function (ratio) {return this;},
>desaturate : Symbol(desaturate, Decl(index.js, 7, 43))
>ratio : Symbol(ratio, Decl(index.js, 8, 23))

whiten: function (ratio) {return this;},
>whiten : Symbol(whiten, Decl(index.js, 8, 45))
>ratio : Symbol(ratio, Decl(index.js, 9, 19))

blacken: function (ratio) {return this;},
>blacken : Symbol(blacken, Decl(index.js, 9, 41))
>ratio : Symbol(ratio, Decl(index.js, 10, 20))

greyscale: function () {return this;},
>greyscale : Symbol(greyscale, Decl(index.js, 10, 42))

clearer: function (ratio) {return this;},
>clearer : Symbol(clearer, Decl(index.js, 11, 39))
>ratio : Symbol(ratio, Decl(index.js, 12, 20))

toJSON: function () {return this.rgb();},
>toJSON : Symbol(toJSON, Decl(index.js, 12, 42))

};
Loading