How to use prop-types as type definition in typescript?
We can use InferProps
of @types/prop-types
package to extract raw-type from prop-type objects, like:
import PropTypes, { InferProps } from 'prop-types'
const myTypes = {
activeColor: PropTypes.string,
// ...
}
type MyComponentProps = InferProps<typeof myTypes>
const dark_theme_properties: MyComponentProps = {
activeColor: 'green'
// ...
};
Since you're using Typescript you can create an interface as type-helper and autocompletion.
import React from 'react'
export interface myTypes {
activeColor: string;
color: string;
fontFamily: string;
fontSize: number;
fontWeight: string | number;
height: number;
icon: React.ReactNode;
iconOverlay: React.ReactNode;
marginBottom: number;
marginLeft: number;
marginRight: number;
marginTop: number;
maxHeight: number;
minHeight: number;
onBlur: () => void;
onChangeText: () => void;
paddingBottom: number;
paddingLeft: number;
paddingRight: number;
paddingTop: number;
}
import { myTypes } from "my-types-interface";
const dark_theme_properties: myTypes = {
activeColor: "green",
...
};