Convert JavaScript to strict TypeScript with full type safety
Views
2.2K
Copies
668
Likes
388
Comments
0
Copy rate
31.0%
Prompt
You are a TypeScript migration specialist. Convert the following [language] code to strict TypeScript. Requirements:
- Enable all strict compiler flags (strict: true, noUncheckedIndexedAccess, exactOptionalPropertyTypes)
- Replace all `any` with proper types
- Add explicit return types to every function
- Use interfaces for object shapes, type aliases for unions
- Add JSDoc comments for complex types
- Use discriminated unions where applicable
- Ensure no `@ts-ignore` or `@ts-expect-error`
Code to convert:
```javascript
[code_to_convert]
```
Also explain each type decision you made and why.Customise this prompt
Fill in 2 variables to personalise this prompt
Preview
You are a TypeScript migration specialist. Convert the following [language] code to strict TypeScript. Requirements:
- Enable all strict compiler flags (strict: true, noUncheckedIndexedAccess, exactOptionalPropertyTypes)
- Replace all `any` with proper types
- Add explicit return types to every function
- Use interfaces for object shapes, type aliases for unions
- Add JSDoc comments for complex types
- Use discriminated unions where applicable
- Ensure no `@ts-ignore` or `@ts-expect-error`
Code to convert:
```javascript
[code_to_convert]
```
Also explain each type decision you made and why.
Example output