질문은 기본적으로 일반적인 JavaScript 방식으로 구현 된 higher-order components의 유형 확인을 보장하는 방법입니다. 유형 검사에 의해상위 주문 구성 요소에 대한 유형 유효성 검사
Hoc1 = (superclass) => class extends superclass { ... }
class A { ... }
class B extends Hoc1(A) { ... }
나는이 가장 눈에 띄는 유틸리티의 사용 의미 : TypeScript 또는 flow. 내가 any
과 거짓 부정적인 미스로
const AMixin: (superclass) => typeof superclass & IAMixinConstructor =
(superclass) => class extends superclass implements IAMixin {
aMixedMethod() {}
}
다음은 superclass
생각이 방법을 믹스 인을 썼다면 내가 타이프에서 다음 코드와 온 지금까지
,
interface IAMixin {
aMixedMethod(): void
}
interface IAMixinConstructor {
new(): IAMixin
}
const AHoc: <T>(superclass: T) => T & IAMixinConstructor = (superclass) =>
class extends superclass implements IAMixin {
aMixedMethod() {}
}
class A {
aMethod() {}
}
class B extends AHoc(A) {
bMethod() {}
}
const b = new B();
b.aMixedMethod(); // false-positive: incrorrectly reports as missing method
b.aMethod();
b.bMethod();
b.cMethod(); // this is correctly caught, though
cMethod
의 호출에 오류가 발생했습니다.
적어도 TypeScript에서는 가능합니다. Object.assign
인스턴스의 경우 올바르게 작동합니다.. 하지만 같은 종류의 건설이 필요합니다. 그러나 클래스의 경우입니다.
또는 Ruby classes과 같은 클래스 유형이 필요합니까?
에서 [타이프 핸드북 (HTTPS 참조 : // www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html)을 참조하십시오. –
새로운 TS 기능에 대해 더 쉽게 읽을 수있는 https://blog.mariusschulz.com/2017/05/26/typescript-2-2-mixin-classes를 찾았습니다. – kirilloid