首页 文章

导入的PropTypes的Intellisense

提问于
浏览
1

由于代码冗余的原因,我将我的实体的PropTypes放在单独的文件中,如:

从'prop-types'导入PropTypes;

export const costCenterBookingPropTypes = PropTypes.shape({
    errorState: PropTypes.bool,
    costCenter: PropTypes.string,
    customerName: PropTypes.string,
    zipCode: PropTypes.number.isRequired,
    city: PropTypes.string,
    startTime: PropTypes.string,
    endTime: PropTypes.string,
    drivingTimeActive: PropTypes.string,
    drivingTimePassive: PropTypes.string,
    breakTime: PropTypes.string,
    loadingTime: PropTypes.string,
    workingTime: PropTypes.string
});

它运行良好,但是当我以这种方式定义PropTypes并将其导入组件并使用它时:

DayOverviewTableDataRow.propTypes = {
    costCenterBooking: costCenterBookingPropTypes
};

然后我的错误状态,zipCode等道具没有智能感知/自动完成功能 .

这是一个已知问题还是我犯了错误?我正在使用WebStorm作为IDE,如果这很重要的话 .

1 回答

  • 0

    您描述的行为只能通过TypeScript实现,并且您必须执行一些(非常繁重的)代码重构 .

    看看这篇中篇文章:React, TypeScript and defaultProps dilemma

相关问题