/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/utils/mixin.ts
20 строк
703 B
Julien Deniau
migrate mixin to TS
24 фев 2025, 11:42
24 фев 2025, 11:42
9e1fb5a
Код
Авторство
О чём код?
type Constructor<T = object> = new (...args: unknown[]) => T; /** * Contributes additional methods to a constructor */ export default function mixin<C extends Constructor>( ctor: C, // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type methods: Record<string, Function> ): C { const keyCopier = (key: string | symbol): void => { // @ts-expect-error how to handle symbol ? ctor.prototype[key] = methods[key]; }; Object.keys(methods).forEach(keyCopier); // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here Object.getOwnPropertySymbols && Object.getOwnPropertySymbols(methods).forEach(keyCopier); return ctor; }