Typescript TSLint:Property';参数';不存在于类型';导航状态';

Typescript TSLint:Property';参数';不存在于类型';导航状态';,typescript,react-native,react-navigation,Typescript,React Native,React Navigation,我在react原生开发中使用typescript。我通过导航功能将参数传递到屏幕 this.props.navigation.navigate("NextScreen", { title: "title" }) 在NextScreen中,我通过this.props.navigation.state.params.title访问参数,但我得到params的tslint错误 TS2339:Property 'params' does not exist on type 'NavigationSta

我在react原生开发中使用typescript。我通过
导航
功能将参数传递到屏幕

this.props.navigation.navigate("NextScreen", { title: "title" })
NextScreen
中,我通过
this.props.navigation.state.params.title
访问参数,但我得到
params
的tslint错误

TS2339:Property 'params' does not exist on type 'NavigationState'.
这是一些代码

import { NavigationInjectedProps } from "react-navigation";
interface OwnProps {
}
interface OwnState {
}

type Props = NavigationInjectedProps & OwnProps;

class NextScreen extends React.Component<Props, OwnState> {
    ...
    public render() {
        // tslint error occurs in this line.
        const { title } = this.props.navigation.state.params;
        ...
    }
}
从“react navigation”导入{NavigationInjectedProps};
界面道具{
}
接口自身状态{
}
类型Props=导航对象Props&OwnProps;
类NextScreen扩展了React.Component{
...
公共渲染(){
//此行中出现tslint错误。
const{title}=this.props.navigation.state.params;
...
}
}

我想我应该定义传球道具的类型,但正确的方法是什么?

像这样提取参数

const {params} = this.props.navigation.state;

const title = params.title

我用这种方法解决了问题,但我不确定这是否是最好的方法。 在研究原始代码时,我使用自定义类型
NavigationScreenProp
重新定义了
navigation

从“反应导航”导入{navigationjectedprops、NavigationScreenProp、NavigationState};
...
接口参数类型{
标题:字符串;
}
接口状态参数扩展了NavigationState{
params:ParamType;
}
界面道具{
导航:导航屏幕弹出;
}
类型Props=OwnProps和navigationjectedprops;

您需要显示所有相关代码。这里的AFAICT不足以回答您的问题。因此,为了清楚起见,该脚本确实有效,但您得到了一个代码分析标志?是的,我得到的是tslint错误,而不是运行时错误或崩溃。@聪明的解决方案,您应该将自己的道具和导航道具结合起来
import { NavigationInjectedProps, NavigationScreenProp, NavigationState } from "react-navigation";
...
interface ParamType {
  title: string;
}
interface StateParams extends NavigationState {
  params: ParamType;
}
interface OwnProps {
  navigation: NavigationScreenProp<StateParams>;
}

type Props = OwnProps & NavigationInjectedProps;