Graphql React Typescript 错误绑定元素 'currency' 隐式具有 'any' 类型
Graphql React Typescript error binding element 'currency' implicitly has an 'any' type
我有这样的案例。我想在 renderedExchangeRates 中使用 EXCHANGE_RATES,但出现错误 “错误消息:绑定元素 'currency' 隐式具有 'any' 类型。”
我知道它是关于类型声明的,但我不知道如何在 data.rates.map(({ currency, rate }) => (...))
.
上正确地写它
This is home functional component....
const { loading, error, data } = useQuery(EXCHANGE_RATES);
const renderedExchangeRates = data.rates.map(({ currency, rate }) => (
<div key={currency}>
<p>
{currency}: {rate}
</p>
</div>
));
return (
...)
错误消息:绑定元素 'currency' 隐式具有 'any' 类型。
我的EXCHANGE_RATES:
import {
ApolloClient,
InMemoryCache,
gql,
} from "@apollo/client";
export const client = new ApolloClient({
uri: "https://48p1r2roz4.sse.codesandbox.io",
cache: new InMemoryCache(),
});
export const EXCHANGE_RATES = gql`
query GetExchangeRates {
rates(currency: "USD") {
currency
rate
}
}
`;
感谢您的关注。
是打字稿编译器的检查。在 tsconfig.json 文件中,您可以更改行
"noImplicitAny": true
如果您想绕过处理类型检查
data.rates.map(({ currency, rate }: { currency: any, rate: any })
我有这样的案例。我想在 renderedExchangeRates 中使用 EXCHANGE_RATES,但出现错误 “错误消息:绑定元素 'currency' 隐式具有 'any' 类型。”
我知道它是关于类型声明的,但我不知道如何在 data.rates.map(({ currency, rate }) => (...))
.
This is home functional component....
const { loading, error, data } = useQuery(EXCHANGE_RATES);
const renderedExchangeRates = data.rates.map(({ currency, rate }) => (
<div key={currency}>
<p>
{currency}: {rate}
</p>
</div>
));
return (
...)
错误消息:绑定元素 'currency' 隐式具有 'any' 类型。
我的EXCHANGE_RATES:
import {
ApolloClient,
InMemoryCache,
gql,
} from "@apollo/client";
export const client = new ApolloClient({
uri: "https://48p1r2roz4.sse.codesandbox.io",
cache: new InMemoryCache(),
});
export const EXCHANGE_RATES = gql`
query GetExchangeRates {
rates(currency: "USD") {
currency
rate
}
}
`;
感谢您的关注。
是打字稿编译器的检查。在 tsconfig.json 文件中,您可以更改行
"noImplicitAny": true
如果您想绕过处理类型检查
data.rates.map(({ currency, rate }: { currency: any, rate: any })