Skip to content

isMethodLike recognises prototype-assignment methods #22935

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 2 commits into from
Mar 28, 2018
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
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16103,7 +16103,9 @@ namespace ts {
}

function isMethodLike(symbol: Symbol) {
return !!(symbol.flags & SymbolFlags.Method || getCheckFlags(symbol) & CheckFlags.SyntheticMethod);
return !!(symbol.flags & SymbolFlags.Method ||
getCheckFlags(symbol) & CheckFlags.SyntheticMethod ||
isInJavaScriptFile(symbol.valueDeclaration) && isFunctionLikeDeclaration(getAssignedJavascriptInitializer(symbol.valueDeclaration)));
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/baselines/reference/typeFromPropertyAssignment23.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/conformance/salsa/a.js ===
class Ex {
>Ex : Symbol(Ex, Decl(a.js, 0, 0))

foo() {
>foo : Symbol(Ex.foo, Decl(a.js, 0, 10))
}
}

class MyClass extends Ex {
>MyClass : Symbol(MyClass, Decl(a.js, 3, 1))
>Ex : Symbol(Ex, Decl(a.js, 0, 0))

}

// this override should be fine (even if it's a little odd)
MyClass.prototype.foo = function() {
>MyClass.prototype.foo : Symbol(MyClass.foo, Decl(a.js, 7, 1))
>MyClass.prototype : Symbol(MyClass.foo, Decl(a.js, 7, 1))
>MyClass : Symbol(MyClass, Decl(a.js, 3, 1))
>prototype : Symbol(MyClass.prototype)
>foo : Symbol(MyClass.foo, Decl(a.js, 7, 1))
}

26 changes: 26 additions & 0 deletions tests/baselines/reference/typeFromPropertyAssignment23.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/conformance/salsa/a.js ===
class Ex {
>Ex : Ex

foo() {
>foo : () => void
}
}

class MyClass extends Ex {
>MyClass : MyClass
>Ex : Ex

}

// this override should be fine (even if it's a little odd)
MyClass.prototype.foo = function() {
>MyClass.prototype.foo = function() {} : () => void
>MyClass.prototype.foo : () => void
>MyClass.prototype : MyClass
>MyClass : typeof MyClass
>prototype : MyClass
>foo : () => void
>function() {} : () => void
}

17 changes: 17 additions & 0 deletions tests/cases/conformance/salsa/typeFromPropertyAssignment23.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @noEmit: true
// @strict: true
// @checkJs: true
// @allowJs: true
// @Filename: a.js
class Ex {
foo() {
}
}

class MyClass extends Ex {

}

// this override should be fine (even if it's a little odd)
MyClass.prototype.foo = function() {
}