我有两个HOC,它们想与redux compose一起使用,但是编译器的类型不正确。Compose声明函数来自redux 源代码。如果我们将代码粘贴到操场上。我们将看到不同类型的第一和第二变量。
type Func1<T1, R> = (a1: T1) => R
type Component<Props> = (props: Props) => string;
declare function compose<T1, A, R>(
f1: (b: A) => R,
f2: Func1<T1, A>
): Func1<T1, R>
declare const HOC1: <Props>(component: Component<Props>)
=> Component<Props & { prop: string }>
declare const HOC2: <Props>(component: Component<Props>)
=> Component<Props & { prop: number }>
declare const component: Component<{props: boolean}>
const first = HOC1(HOC2(component));
const second = compose(HOC1, HOC2)(component);
Run Code Online (Sandbox Code Playgroud) 我对泛型类型有一些问题.我想检查泛型类型是否符合某些协议,并在传递给另一个泛型函数之后.例如我有功能:
func requestSignal<T:Mappable>(target:Api) -> SignalProducer<[T], NSError>
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
func request<T>(target:Api, withObjectType type: T.Type) {
if let mappableType = type as? Mappable.Type {
let requestSignal: SignalProducer<[?????], NSError> = self.requestSignal(target) }
Run Code Online (Sandbox Code Playgroud)
但如果我尝试传递T - 它不符合Mappable.
如果传递mappableType - 它不是一个类型
我有这样的父类:
export class BaseForm {
@Output() public eventSubmit:EventEmitter<any> = new EventEmitter<any>();
public emitForm() :void {
const params = this.getParams();
this.eventSubmit.emit(params);
}
public onSubmit(){
if (!this.isValid) {
return;
}
this.emitForm()
}
}
Run Code Online (Sandbox Code Playgroud)
和孩子:
@Component({
selector: 'app-auth-form',
templateUrl: './auth-form.component.html',
styleUrls: ['./auth-form.component.styl'],
})
export class AuthFormComponent extends BaseForm { }
Run Code Online (Sandbox Code Playgroud)
然后我尝试绑定另一个组件,如下所示:
<app-auth-form
(eventSubmit)="tap($event)"
[error]="error">
</app-auth-form>
Run Code Online (Sandbox Code Playgroud)
tap只是显示发出的数据.所以,然后我在BaseForm中发出一些东西,我在日志中没有任何东西.有任何想法吗?
typescript ×2
angular ×1
compose-db ×1
generics ×1
ios ×1
protocols ×1
reactjs ×1
redux ×1
request ×1
swift ×1