You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{NextPage,NextPageContext}from'next';constMyComponent: NextPage<MyPropsInterface>=props=>(// ...)interfaceContextextendsNextPageContext{// any modifications to the default context, e.g. query types}MyComponent.getInitialProps=async(ctx: Context)=>{// ...returnprops}
react组件文件名必须以tsx结尾
否则可能会报'SomeComponent' refers to a value, but is being used as a type here.
react + next.js + typescript配置
由于之前对typescript不熟悉,所以记录一下流程
yarn dev # 此处是样例,输入你的启动服务命令
nexts.js会自动配置tsconfig.json并创建一个next-env.d.ts文件
example:
paths下的路径都是以baseUrl为基础解析,所以@/开头的路径都会到src目录下去解析。baseUrl必须配置。
先安装依赖
声明主题文件, 按照自己的theme对象包含的属性修改。e.g.:
所有class的属性必须声明在类代码块中, 根据需要选择修饰符
private
orpublic
e.g.
参考: https://stackoverflow.com/questions/50451854/trouble-with-typescript-typing-for-store-enhancers-in-redux-4-0
https://stackoverflow.com/a/57441122
否则可能会报'SomeComponent' refers to a value, but is being used as a type here.
microsoft/TypeScript#15713 (comment)
在泛型后面加一个逗号
https://stackoverflow.com/questions/57472105/react-redux-useselector-typescript-type-for-state
引入ThunkAction作为返回类型, 需要定义四个泛型类型<R, S, E, A>
R是最后ThunkAction的返回类型,S是State,E是ThunkAction额外参数(这里没有用到),A是ThunkDispatch即
dispatch
参数接受的action类型,可以是普通action也可以是ThunkAction。xxx is not assignable to type xxx
声明Props的定义
函数式组件
Class组件
The text was updated successfully, but these errors were encountered: