We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Code
function extend<First, Second>(first: First, second: Second): First & Second { const result: Partial<First & Second> = {}; for (const prop in first) { if (first.hasOwnProperty(prop)) { (result as First)[prop] = first[prop]; } } for (const prop in second) { if (second.hasOwnProperty(prop)) { (result as Second)[prop] = second[prop]; } } return result as First & Second; } class Person { constructor(public name: string) { } } interface Loggable { log(name: string): void; } class ConsoleLogger implements Loggable { log(name) { console.log(`Hello, I'm ${name}.`); } } const jim = extend(new Person('Jim'), ConsoleLogger.prototype); jim.log(jim.name);
class methods are non-enumerable, so the second for...in loop will not add log method to the result obj.
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Code
class methods are non-enumerable, so the second for...in loop will not add log method to the result obj.
The text was updated successfully, but these errors were encountered: