i have 2 similar questions : I`ve been working with the typescript recently, but i need my styled-component code to be validate to typescript.
1. I need describe custom prop - shadow, because typescript return error
Property 'shadow' does not exist on type 'ThemedStyledProps, HTMLDivElement>, "color" | "style" | "title" | ... 251 more ... | "key"> & { ...; } & { ...; }, DefaultTheme>'. TS2339
export const InputBlock = styled.div<{height: string}>`
display: flex;
width: 100%;
height: ${props => (props.height ? props.height : "56px")};
${props =>
props.shadow &&
css`
box-shadow: ${props =>
props.shadow ? "4px 4px 10px rgba(31,31,31,0.1)" : "none"};
`};
`;
2. how can i describe this props.touched[props.name] in my interface
interface FormSchema {
errors: {
[name: string]?: string, // ????
},
touched: {
[propName: string]?: string, // ???
},
value: string,
theme: {
color: {
redError?:string,
inactiveBlue?:string,
green?:string,
}
}
}
const colorStateForm = (props: FormSchema) =>
props.errors &&
props.touched &&
props.errors[props.name] &&
props.touched[props.name]
? props.theme.color.redError
: !props.value && (!props.value.length || props.value.length === 0)
? props.theme.color.inactiveBlue
: props.theme.color.green;
I used Formik and Yup for my form