打字稿一般类型错误
Typescript Generic type error
我有一个实用函数,它在注入存储以响应组件时进行类型级别检查。
import { Omit } from 'typelevel-ts';
import * as React from 'react';
declare module 'mobx-react' {
export function inject<D>(
mapStoreToProps: (store) => D
): <A extends D>(component: React.ComponentType<A>) =>
React.SFC<Omit<A, keyof D> & Partial<D>>;
}
使用最新的打字稿版本 2.9.2 我收到错误 "Type 'A' does not satisfy the constraint 'object'.Type 'D' is not assignable to type 'object'."
能否请您帮助理解此错误以及可能的解决方法。
谢谢
看起来 Omit
要求第一个泛型是一个对象,因此如果您为 D:
添加该约束,它应该可以工作
export function inject<D extends object>(
我有一个实用函数,它在注入存储以响应组件时进行类型级别检查。
import { Omit } from 'typelevel-ts';
import * as React from 'react';
declare module 'mobx-react' {
export function inject<D>(
mapStoreToProps: (store) => D
): <A extends D>(component: React.ComponentType<A>) =>
React.SFC<Omit<A, keyof D> & Partial<D>>;
}
使用最新的打字稿版本 2.9.2 我收到错误 "Type 'A' does not satisfy the constraint 'object'.Type 'D' is not assignable to type 'object'."
能否请您帮助理解此错误以及可能的解决方法。
谢谢
看起来 Omit
要求第一个泛型是一个对象,因此如果您为 D:
export function inject<D extends object>(