Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

fix the non-enumerable of the class prototype #1058

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions pages/Advanced Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ You will mostly see intersection types used for mixins and other concepts that d
Here's a simple example that shows how to create a mixin:

```ts
function extend<First, Second>(first: First, second: Second): First & Second {
function extend<First extends {}, Second extends {}>(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];
Object.getOwnPropertyNames(second).forEach(prop => {
if (prop !== 'constructor' && prop in second) {
(result as any)[prop] = (second as any)[prop]
}
}
})
return result as First & Second;
}

Expand Down