Instruction file imported from equinor/design-system (
.github/instructions/ts.instructions.md). Copyright stays with the author.
TypeScript Guidelines
See
AGENTS.mdfor the canonical conventions. This file adds TS-specific guidance for Copilot.
Type Definitions
typealiases for component props — matches the pattern in/nextand supports intersection types (& Omit<...>) cleanly- Union types for constrained options (e.g.,
'primary' | 'secondary'instead ofstring) - Explicit typing where clarity matters; inference for obvious cases
- Immutable data (const, readonly properties)
- Avoid
anyunless impossible; useunknownif needed - Extend definitions rather than duplicating
// ✅ Good
export type ButtonProps = {
variant: 'primary' | 'secondary'
disabled?: boolean
} & ButtonHTMLAttributes<HTMLButtonElement>
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {}
// ❌ Avoid
type ButtonVariant = string
const handleClick = (event: any) => {}
Functional Programming
- Pure functions where possible
- Avoid state mutations
- Optional chaining
?.and nullish coalescing?? - Prefer
constoverlet
Testing
Testing Library priorities:
- Query by role:
getByRole('button', { name: /submit/i }) - Query by accessible name:
getByText('Submit') - Query by label:
getByLabelText('Username') - Last resort:
getByTestId('submit-btn')
Test structure:
test('Button displays loading state when disabled', () => {
render(<Button disabled>Loading</Button>);
const button = screen.getByRole('button');
expect(button).toBeDisabled();
});
Formatting rules:
- No blank lines between render and assertions
- Group related assertions together
- One blank line between test cases
- Descriptive test names explaining behavior
Coverage:
- User interactions (clicks, keyboard, focus)
- Accessibility (ARIA, keyboard navigation)
- Edge cases and error states
- Props variations
Anti-patterns:
// ❌ Implementation testing
test('state updates', () => {
// testing internal state, not user behavior
})
// ✅ Behavior testing
test('Button shows success message when form is submitted', () => {
// testing what user sees
})