简体   繁体   English

元素指的是一个值,但在这里被用作类型

[英]element refers to a value, but is being used as a type here

I have the following code:我有以下代码:

export const StateContext = createContext({});
const StoreProvider: any = StateContext.Provider;
export const StateProvider = ({ reducer, initialState, children }: any) => (
  <StoreProvider value={useReducer(reducer: any, initialState: any)}>
    {children}
  </StoreProvider>
);

but TypeScript is throwing an error 'StoreProvider' refers to a value, but is being used as a type here.但 TypeScript 抛出错误'StoreProvider' refers to a value, but is being used as a type here. - why? - 为什么? I assume its seeing it as a generic, but how to make it see as is needed?我假设它把它看作是一个通用的,但如何让它看起来像需要的那样?

I got the same error on my project and solve the problem.我在我的项目中遇到了同样的错误并解决了问题。 Maybe your filename extension is ts, not tsx.也许您的文件扩展名是 ts,而不是 tsx。 If you are using Parcel or so on, the compiler considers that the file doesn't use React.如果您使用的是 Parcel 等,编译器会认为该文件没有使用 React。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &#39;ItemIsLoading&#39;on指的是一种类型,但此处被用作值 - 'ItemIsLoading' on refers to a type, but is being used as a value here 指的是一个值,但在这里被用作一个类型 - refers to a value, but is being used as a type here 导出时类型“仅指一种类型,但在此处用作值” - Type “only refers to a type, but is being used as a value here” when exporting &#39;MapEditServiceConfig&#39;仅引用类型,但在此处用作值 - 'MapEditServiceConfig' only refers to a type, but is being used as a value here “承诺”仅指类型,但在此处用作值 - 'Promise' only refers to a type, but is being used as a value here “&#39;输出&#39;仅指一种类型,但在此处使用了一个值”错误 - "'Output' only refers to a type, but is being used a value here" error “post”仅指一种类型,但在此处用作值 - 'post' only refers to a type, but is being used as a value here ionic 'DocumentScanner' 指的是一个值,但在这里被用作一个类型 - ionic 'DocumentScanner' refers to a value, but is being used as a type here IFormContext 只引用一个类型,但在这里用作一个值 - IFormContext only refers to a type, but is used as a value here “导航栏指的是一个值,但在这里被用作一种类型”在测试时尝试渲染我的组件的浅表副本 - “Navbar refers to a value, but is being used as a type here” when trying to render a shallow copy of my component when testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM