mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Allow JS constructor function to return non-void
This commit is contained in:
22
tests/cases/compiler/jsConstructorFunction.ts
Normal file
22
tests/cases/compiler/jsConstructorFunction.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @filename: index.js
|
||||
// @lib: es5, dom
|
||||
var Person = function (firstNameOrPojo, lastName) {
|
||||
|
||||
if (typeof firstNameOrPojo === "string") {
|
||||
this.firstName = firstNameOrPojo;
|
||||
this.lastName = lastName;
|
||||
} else {
|
||||
return new Person(firstNameOrPojo.firstName, firstNameOrPojo.lastName);
|
||||
}
|
||||
};
|
||||
|
||||
Person.prototype.greet = function greet() {
|
||||
return `Hello, I am ${this.firstName} ${this.lastName}.`;
|
||||
};
|
||||
|
||||
var fred = new Person({ firstName: "Fred", lastName: "Flintstone" });
|
||||
|
||||
console.log(fred.greet());
|
||||
Reference in New Issue
Block a user