Auto check examples in /components/docs #2175
Replies: 2 comments 2 replies
-
PR's for Typescript fixes are always welcome. |
Beta Was this translation helpful? Give feedback.
-
To automatically check the TypeScript types in your 1. Automated Testing with TypeScript CompilerYou can use the TypeScript compiler (
2. Using ESLint with TypeScriptSet up ESLint with the TypeScript parser to lint your examples. This not only checks for type errors but also enforces code style and best practices.
3. Unit Testing with Type AssertionsWrite unit tests that specifically assert type compatibility. Tools like
4. Custom ToolingFor a more tailored solution, develop a custom tool that:
5. Manual Review Enhanced with ToolingWhile automated checks are valuable, they might not catch everything, especially nuances in how components are supposed to be used versus how they are documented. Combining automated tooling with periodic manual reviews could provide a balance between automation and accuracy.
Next Steps
This approach will help you maintain a high standard for your TypeScript examples, reducing the likelihood of errors making their way into user code. |
Beta Was this translation helpful? Give feedback.
-
While looking at primefaces/primereact#6774, I found a variety of other components for which the TypeScript types seem to be slightly off. Therefore my question: Is there a way to automatically check the types of Typescript examples in the `/components/docs folder? All problems here will end up as errors in the code of the users. So ideally these code examples are validated for type problems and other errors.
Steps to reproduce:
npm install && npm run dev
to completehttps://primereact.org/stepper/#basic
Type '{ children: Element[]; ref: MutableRefObject<null>; style: { flexBasis: string; }; }' is not assignable to type 'IntrinsicAttributes & StepperProps & { children?: ReactNode; } & RefAttributes<StepperRefAttributes>'. Property 'style' does not exist on type 'IntrinsicAttributes & StepperProps & { children?: ReactNode; } & RefAttributes<StepperRefAttributes>'
'stepperRef.current' is possibly 'null'.
https://primereact.org/floatlabel/#basic
Type '{ children: string; for: string; }' is not assignable to type 'DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>'. Property 'for' does not exist on type 'DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>'. Did you mean 'htmlFor'?
https://primereact.org/inputotp/#template
Cannot find name 'InputHTMLAttributes'.
Type '({ events, props }: CustomInputProps) => JSX.Element' is not assignable to type 'TemplateType<InputOtpProps>'. Type '({ events, props }: CustomInputProps) => JSX.Element' is not assignable to type '(props: InputOtpProps) => ReactNode'. Types of parameters '__0' and 'props' are incompatible. Type 'InputOtpProps' is missing the following properties from type 'CustomInputProps': events, props
Alternatives
If an automatic check is not feasible, it would make sense to go through the TypeScript examples manually and correct the type annotations.
Beta Was this translation helpful? Give feedback.
All reactions