react-router-domのLinkコンポネントを基にstyled-componentとtypescriptで、スタイルを適用したLinkコンポネントを作ろうとしています。
以下Linkコンポネント部分のソースコードです
import React from 'react'; import { Link as RouterLink, LinkProps } from 'react-router-dom'; import styled from 'styled-components'; export const Link: React.FC<LinkProps> = props => <StyledLink {...props} />; const StyledLink = styled(RouterLink)` text-decoration: none; `
いくつかのサイト通りにコードを書きましたが以下のエラーがでてしまいます。
TS2769: No overload matches this call. Overload 1 of 2, '(props: Pick<Pick<LinkProps<unknown> & RefAttributes<Link<unknown>>, "style" | "title" | "type" | "ref" | "component" | "to" | "replace" | "innerRef" | "download" | ... 259 more ... | "key"> & Partial<...>, "style" | ... 267 more ... | "key"> & { ...; } & { ...; } & { ...; }): ReactElement<...>', gave the following error. Type '{ component?: ComponentClass<any, any> | FunctionComponent<any> | undefined; to: string | LocationDescriptorObject<PoorMansUnknown> | ((location: Location<...>) => LocationDescriptor<...>); ... 264 more ...; onTransitionEndCapture?: ((event: TransitionEvent<...>) => void) | undefined; }' is not assignable to type 'Pick<Pick<LinkProps<unknown> & RefAttributes<Link<unknown>>, "style" | "title" | "type" | "ref" | "component" | "to" | "replace" | "innerRef" | "download" | ... 259 more ... | "key"> & Partial<...>, "style" | ... 267 more ... | "key">'. Types of property 'to' are incompatible. Type 'string | LocationDescriptorObject<PoorMansUnknown> | ((location: Location<PoorMansUnknown>) => LocationDescriptor<PoorMansUnknown>)' is not assignable to type 'string | LocationDescriptorObject<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'. Type '(location: Location<PoorMansUnknown>) => LocationDescriptor<PoorMansUnknown>' is not assignable to type 'string | LocationDescriptorObject<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'. Type '(location: Location<PoorMansUnknown>) => LocationDescriptor<PoorMansUnknown>' is not assignable to type '(location: Location<unknown>) => LocationDescriptor<unknown>'. Types of parameters 'location' and 'location' are incompatible. Type 'Location<unknown>' is not assignable to type 'Location<PoorMansUnknown>'. Type 'unknown' is not assignable to type 'PoorMansUnknown'. Type 'unknown' is not assignable to type '{}'. Overload 2 of 2, '(props: StyledComponentPropsWithAs<typeof Link, any, {}, never>): ReactElement<StyledComponentPropsWithAs<typeof Link, any, {}, never>, string | ... 1 more ... | (new (props: any) => Component<...>)>', gave the following error. Type '{ component?: ComponentClass<any, any> | FunctionComponent<any> | undefined; to: string | LocationDescriptorObject<PoorMansUnknown> | ((location: Location<...>) => LocationDescriptor<...>); ... 264 more ...; onTransitionEndCapture?: ((event: TransitionEvent<...>) => void) | undefined; }' is not assignable to type 'Pick<Pick<LinkProps<unknown> & RefAttributes<Link<unknown>>, "style" | "title" | "type" | "ref" | "component" | "to" | "replace" | "innerRef" | "download" | ... 259 more ... | "key"> & Partial<...>, "style" | ... 267 more ... | "key">'. Types of property 'to' are incompatible. Type 'string | LocationDescriptorObject<PoorMansUnknown> | ((location: Location<PoorMansUnknown>) => LocationDescriptor<PoorMansUnknown>)' is not assignable to type 'string | LocationDescriptorObject<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'. Type '(location: Location<PoorMansUnknown>) => LocationDescriptor<PoorMansUnknown>' is not assignable to type 'string | LocationDescriptorObject<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'. Type '(location: Location<PoorMansUnknown>) => LocationDescriptor<PoorMansUnknown>' is not assignable to type '(location: Location<unknown>) => LocationDescriptor<unknown>'.
解決策を教えていただけないでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。