lovable-boilerplate / rules
Cursor rule65 starsChanged 16 months agoMITView on GitHub
TypeScript type definitions and utility patterns for the application
- Reads credentials
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository8 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/components.mdcCursor rule
- .cursor/rules/core.mdcCursor rule
- .cursor/rules/design.mdcCursor rule
- .cursor/rules/forms.mdcCursor rule
- .cursor/rules/hooks.mdcCursor rule
- .cursor/rules/quality.mdcCursor rule
- .cursor/rules/services.mdcCursor rule
The file
We split this typescript.mdc into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 178
Not leveraging Zod for runtime validation
- Distinctive: line 183
Use Zod schemas for validation and type inference
- Distinctive: line 185
Use proper generic constraints
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: TypeScript type definitions and utility patterns for the application
globs: ["src/lib/types.ts", "src/lib/utils.ts", "src/lib/constants.ts"]
alwaysApply: false
---
# TypeScript & Utilities Rules
## Shared Type Definitions
### Core Application Types
```tsx
// lib/types.ts - Always define shared types here
export interface User {
id: string
email: string
name: string
avatar?: string
role: UserRole
createdAt: string
updatedAt: string
}
export interface ApiResponse<T> {
data: T
message: string
success: boolean
meta?: {
total: number
page: number
limit: number
}
}
export type UserRole = 'admin' | 'user' | 'guest'
export type Theme = 'light' | 'dark' | 'system'
export type LoadingState = 'idle' | 'loading' | 'success' | 'error'
```
### Form Type Patterns
```tsx
// Derive form types from Zod schemas
export type UserFormData = z.infer<typeof userSchema>
export type CreateUserData = z.infer<typeof createUserSchema>
export type UpdateUserData = z.infer<typeof updateUserSchema>
// Component prop types
export interface UserCardProps {
user: User
onEdit: (id: string) => void
onDelete: (id: string) => void
className?: string
}
```
## Utility Functions
### Keep Existing cn Function
```tsx
// lib/utils.ts - NEVER modify this function
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
```
### Common Utility Patterns
```tsx
// Date formatting
export function formatDate(date: Date | string, format?: string): string {
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
...format
}).format(new Date(date))
}
// Debounce utility
export function debounce<T extends (...args: any[]) => any>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout
return (...args: Parameters<T>) => {
clearTimeout(timeout)
timeout = setTimeout(() => func(...args), wait)
}
}
// Sleep utility for demos/testing
export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
```
## Constants Organization
### API and Route Constants
```tsx
// lib/constants.ts
export const API_ENDPOINTS = {
USERS: '/api/users',
PRODUCTS: '/api/products',
AUTH: '/api/auth',
} as const
export const QUERY_KEYS = {
USERS: 'users',
PRODUCTS: 'products',
USER_PROFILE: 'user-profile',
} as const
export const ROUTES = {
HOME: '/',
DASHBOARD: '/dashboard',
USERS: '/users',
PROFILE: '/profile',
} as const
```
### Configuration Constants
```tsx
export const APP_CONFIG = {
APP_NAME: 'My App',
API_BASE_URL: import.meta.env.VITE_API_URL || 'http://localhost:3000',
ITEMS_PER_PAGE: 10,
MAX_FILE_SIZE: 5 * 1024 * 1024, // 5MB
} as const
export const BREAKPOINTS = {
sm: '640px',
md: '768px',
lg: '1024px',
xl: '1280px',
'2xl': '1536px',
} as const
```
## TypeScript Best Practices
### Generic Patterns
```tsx
// API response wrapper
export interface PaginatedResponse<T> {
data: T[]
meta: {
total: number
page: number
limit: number
totalPages: number
}
}
// Generic hook return type
export interface UseQueryResult<T> {
data: T | undefined
isLoading: boolean
error: Error | null
refetch: () => void
}
```
### Environment Variables Typing
```tsx
// vite-env.d.ts additions
interface ImportMetaEnv {
readonly VITE_API_URL: string
readonly VITE_APP_NAME: string
// Add more environment variables as needed
}
interface ImportMeta {
readonly env: ImportMetaEnv
}
```
## Type Anti-Patterns
- Using `any` type
- Inline interface definitions in components
- Not leveraging Zod for runtime validation
- Duplicate type definitions across files
## Type Best Practices
- Define shared types in `lib/types.ts`
- Use Zod schemas for validation and type inference
- Leverage TypeScript strict mode
- Use proper generic constraints
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

