简单地从文档中粘贴示例代码
import { createCanBoundTo } from '@casl/react';
import ability from './abilities';
export const Can = createCanBoundTo(ability);
在最后一行给出错误:
导出的变量'Can'具有或正在使用来自外部模块"C:/Users/ahmefa04/Documents/SourceCode/temp-cd-next/node_modules/@casl/react/dist/types/factory"的名称'BoundCanClass',但不能命名为. ts(4023)
编辑:我在factory. d. ts文件中导出了BoundCanClass,但是当我尝试在应用程序中使用can时:
<Can I="view" on="all">
<Button size="small" onClick={handleUpdateRow}>
Update a user
</Button>
</Can>
我得到错误:
No overload matches this call. Overload 1 of 2, '(props: BoundCanProps<Ability<AbilityTuple<string, Subject>, { published: boolean; }>>, context?: any): Can<Ability<AbilityTuple<string, Subject>, { ...; }>, true>', gave the following error. Type '{ children: Element[]; I: string; on: string; }' is not assignable to type 'IntrinsicAttributes & (IntrinsicClassAttributes<Can<Ability<AbilityTuple<string, Subject>, { published: boolean; }>, true>> & (Readonly<...> & Readonly<...>))'. Property 'this' is missing in type '{ children: Element[]; I: string; on: string; }' but required in type 'Readonly<{ I: string; this: AnyRecord; field?: string | undefined; } & BoundCanExtraProps<Ability<AbilityTuple<string, Subject>, { published: boolean; }>>>'. Overload 2 of 2, '(props: BoundCanProps<Ability<AbilityTuple<string, Subject>, { published: boolean; }>>, context?: any): Component<BoundCanProps<Ability<AbilityTuple<string, Subject>, { ...; }>>, any, any>', gave the following error. Type '{ children: Element[]; I: string; on: string; }' is not assignable to type 'IntrinsicAttributes & (IntrinsicClassAttributes<Component<BoundCanProps<Ability<AbilityTuple<string, Subject>, { published: boolean; }>>, any, any>> & (Readonly<...> & Readonly<...>))'. Property 'this' is missing in type '{ children: Element[]; I: string; on: string; }' but required in type 'Readonly<{ I: string; this: AnyRecord; field?: string | undefined; } & BoundCanExtraProps<Ability<AbilityTuple<string, Subject>, { published: boolean; }>>>'.ts(2769)
1条答案
按热度按时间vngu2lb81#
出现问题的原因是
I
应该与a
、an
或this
prop 一起使用,要使用on
,您应该使用do
:或
文件参考