Xii*_*ryo 9 typescript react-native react-navigation react-navigation-stack react-navigation-v5
使用 TypeScript 3.9、React Native、React 导航...
我收到错误:
interface StackParamList
Type 'StackParamList' does not satisfy the constraint 'Record<string, object | undefined>'.
Index signature is missing in type 'StackParamList'.ts(2344)
Run Code Online (Sandbox Code Playgroud)
在:
const HomeStack = createStackNavigator<StackParamList>()
Run Code Online (Sandbox Code Playgroud)
在:
interface StackParamList
Type 'StackParamList' does not satisfy the constraint 'Record<string, object | undefined>'.
Index signature is missing in type 'StackParamList'.ts(2344)
Run Code Online (Sandbox Code Playgroud)
我不明白为什么接口不满足类型 'Record<string, object | 未定义>'。
我不明白“索引签名丢失”是什么意思。
你有好主意吗?
谢谢
jef*_*wis 13
我可以通过更改输入界面来解决这个问题。这是 StackOverflow 帖子的链接。
错误修复:
// TypeScript Type: Stack Param List
export type StackParamList = {
Home: undefined
Post: { post: Post }
Category: { category: Category }
Login: undefined
ForgotPassword: undefined
'My profile': undefined
'My partner': undefined
Parameters: undefined
Likes: undefined
Onboarding: undefined
};
Run Code Online (Sandbox Code Playgroud)
Xii*_*ryo -2
我通过添加以下内容解决了这个问题:
| Record<string, object | undefined>
Run Code Online (Sandbox Code Playgroud)
在:
export type StackParamList =
| {
Home: undefined
Post: { post: Post }
Category: { category: Category }
Login: undefined
ForgotPassword: undefined
'My profile': undefined
'My partner': undefined
Parameters: undefined
Likes: undefined
Onboarding: undefined
}
| Record<string, object | undefined>
Run Code Online (Sandbox Code Playgroud)
我还是不太明白为什么需要它......
| 归档时间: |
|
| 查看次数: |
15465 次 |
| 最近记录: |