Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 接口不满足约束';记录<;字符串,对象|未定义>';。类型'中缺少索引签名;StackParamList';。ts(2344)_Typescript_React Native_React Navigation_React Navigation Stack_React Navigation V5 - Fatal编程技术网

Typescript 接口不满足约束';记录<;字符串,对象|未定义>';。类型'中缺少索引签名;StackParamList';。ts(2344)

Typescript 接口不满足约束';记录<;字符串,对象|未定义>';。类型'中缺少索引签名;StackParamList';。ts(2344),typescript,react-native,react-navigation,react-navigation-stack,react-navigation-v5,Typescript,React Native,React Navigation,React Navigation Stack,React Navigation V5,使用TypeScript 3.9,反应本机,反应导航 我得到一个错误: interface StackParamList Type 'StackParamList' does not satisfy the constraint 'Record<string, object | undefined>'. Index signature is missing in type 'StackParamList'.ts(2344) 接口列表 类型“StackParamList”不满足约

使用TypeScript 3.9,反应本机,反应导航

我得到一个错误:

interface StackParamList
Type 'StackParamList' does not satisfy the constraint 'Record<string, object | undefined>'.
  Index signature is missing in type 'StackParamList'.ts(2344)
接口列表
类型“StackParamList”不满足约束“Record”。
类型“StackParamList.ts”中缺少索引签名(2344)
关于:

const HomeStack=createStackNavigator()
在:

const HomeStack=createStackNavigator()
导出接口列表{
主页:未定义
Post:{Post:Post}
类别:{Category:Category}
登录:未定义
放弃密码:未定义
“我的个人资料”:未定义
“我的搭档”:未定义
参数:未定义
喜欢:未定义
入职:未定义
}
/**
*主“堆栈导航器”
*@summary这是“主页”下所有内容的导航器
*/
导出默认函数HomeStackScreen(){
返回(
,
}}
/>
({title:route.params.category.id}/>
)
}
我不明白为什么接口不能满足“Record”类型

我不明白“缺少索引签名”是什么意思

你有什么想法吗


谢谢

我通过添加以下内容解决了这个问题:

| Record<string, object | undefined>
|记录
关于:

导出类型列表=
| {
主页:未定义
Post:{Post:Post}
类别:{Category:Category}
登录:未定义
放弃密码:未定义
“我的个人资料”:未定义
“我的搭档”:未定义
参数:未定义
喜欢:未定义
入职:未定义
}
|记录

我仍然不明白为什么需要它…

我通过将接口更改为type来解决这个问题

错误修复:

// 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
};
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>
// 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
};