Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

reactjs - TypeScript equivalent of PropTypes.array and PropTypes.object?

What is the TypeScript equivalent of this?

sessions: PropTypes.oneOfType([
    PropTypes.array,
    PropTypes.object,
]).isRequired,

I translated this to the following 'point':

export type Sessions = [Object | Array];

However, I'm not sure how I should replace PropTypes.array and PropTypes.object.

question from:https://stackoverflow.com/questions/65831253/typescript-equivalent-of-proptypes-array-and-proptypes-object

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can consider this

type TypeSessions = Object | Array;
const sessions: TypeSessions = [];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...