Instruction file imported from Pericles-Cloud/pericles (
.cursor/rules/300-languages/307-typescript-core-standards-auto.mdc). Copyright stays with the author.
// main.ts import { util1, util2 } from './utils'; ]]>
<!-- Section 2: Common Patterns and Anti-patterns -->
<non-negotiable priority="critical">
<description>Avoid using the `any` type. Use specific types, generics, or `unknown` instead to maintain type safety.</description>
<examples>
<example title="Usage of 'any'">
<correct-example title="Using a specific type"><![CDATA[
function processData(data: { id: number; name: string }) { /* ... */ } ]]> Break down long functions into smaller, single-responsibility functions. Use constants for magic numbers and strings to improve readability and maintainability. Always handle errors gracefully. Do not use empty catch blocks, as this can hide critical issues.
<!-- Section 3: Performance Considerations -->
<requirement priority="medium">
<description>Use memoization (e.g., React.memo, useMemo) to prevent unnecessary computations and re-renders in UI applications.</description>
</requirement>
<requirement priority="medium">
<description>Implement lazy loading for modules and components that are not immediately needed using dynamic imports.</description>
<examples>
<example title="Lazy Loading">
<correct-example title="Dynamic Import in React"><![CDATA[
import React, { Suspense } from 'react';
const MyComponent = React.lazy(() => import('./MyComponent'));
function App() { return ( <Suspense fallback={Loading...}> ); } ]]>
<!-- Section 4: Security Best Practices -->
<non-negotiable priority="critical">
<description>Sanitize user input and escape output to prevent Cross-Site Scripting (XSS) attacks.</description>
</non-negotiable>
<non-negotiable priority="critical">
<description>Use parameterized queries or ORMs to prevent SQL injection attacks in backend TypeScript code.</description>
</non-negotiable>
<non-negotiable priority="critical">
<description>Validate all user input on both the client and server sides.</description>
</non-negotiable>
<!-- Section 5: Testing Approaches -->
<requirement priority="high">
<description>Write unit tests for individual functions and components, testing edge cases and error conditions.</description>
</requirement>
<requirement priority="medium">
<description>Use integration tests to verify that different parts of the application work together correctly.</description>
</requirement>
<!-- Section 6: Common Pitfalls and Gotchas -->
<requirement priority="high">
<description>Handle asynchronous operations correctly using Promises and async/await syntax, including proper error handling.</description>
</requirement>
<!-- Section 7: Tooling and Environment -->
<requirement priority="high">
<description>Use a linter (like ESLint) and a formatter (like Prettier) to enforce consistent code style and catch issues early.</description>
</requirement>
<requirement priority="high">
<description>Configure the TypeScript compiler via `tsconfig.json`, enabling `strict` mode and other strict checks to leverage TypeScript's full potential.</description>
<examples>
<example title="tsconfig.json">
<correct-example title="Strict configuration"><![CDATA[
{ "compilerOptions": { "strict": true, "noImplicitAny": true, "strictNullChecks": true, "forceConsistentCasingInFileNames": true } } ]]> Base rule format definition