Copilot instructions for TypeScript project setup covering strict tsconfig flags and their effects, type-only imports, module hygiene and TSDoc for public APIs.
.github/instructions/github-copilot-typescript.instructions.md. Downloaded files need to be placed in that repository path.---
applyTo: "**/*"
---
# TypeScript Project Instructions
Applies to: TypeScript configuration, public module APIs and their documentation in this repository.
Version baseline: checked against TypeScript 5.9 and the TSConfig reference. Read `tsconfig.json` and `package.json` first; do not change compiler options unless the task asks for it.
## Compiler settings
Recommended strictness for new projects (keep the project's existing values otherwise):
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true
}
}
```
- `noUncheckedIndexedAccess` makes `arr[i]` and `record[key]` return `T | undefined`; handle the `undefined` case instead of adding `!`.
- `exactOptionalPropertyTypes` makes `{ name?: string }` reject an explicit `name: undefined`; write `name?: string | undefined` when callers really pass `undefined`.
- Turning on a flag in an existing codebase is its own change: report the error count and fix files in a separate step.
## Type safety
- No `any` in new code. Use `unknown` for untrusted values and narrow it.
- No non-null `!` or `as` casts to silence errors; if one is unavoidable, add a comment with the reason.
- No `@ts-ignore`; use `@ts-expect-error` with a reason, so the comment fails once it is no longer needed.
## Modules and imports
- With `verbatimModuleSyntax`, import types with `import type { User } from './user'`.
- Export only what other modules use; keep helpers file-local.
- Avoid barrel files (`index.ts` that re-exports everything) in application code when they create import cycles or slow builds; follow the project's existing convention.
- Follow the project's module system (`"type": "module"`, file extensions in relative imports when `moduleResolution` is `NodeNext`).
## Documenting public APIs (TSDoc/JSDoc)
Document exported functions, classes and types that other modules or packages consume. Describe behavior, units, errors and edge cases; do not repeat the types.
```ts
/**
* Splits `items` into pages of `size` elements.
*
* @param items - Items in display order. Not modified.
* @param size - Page size; must be a positive integer.
* @returns One array per page; the last page may be shorter.
* @throws RangeError if `size` is not a positive integer.
*
* @example
* paginate([1, 2, 3], 2); // [[1, 2], [3]]
*/
export function paginate<T>(items: readonly T[], size: number): T[][] {
if (!Number.isInteger(size) || size <= 0) {
throw new RangeError('size must be a positive integer');
}
const pages: T[][] = [];
for (let i = 0; i < items.length; i += size) {
pages.push(items.slice(i, i + size));
}
return pages;
}
```
- Keep `@example` blocks runnable and correct; update them when behavior changes.
- Mark deprecated APIs with `@deprecated` and name the replacement.
## Verify before finishing
Run these when they are available in the project:
- `npx tsc --noEmit` (or the project's `typecheck` script)
- the linter (`npx eslint .`), including `@typescript-eslint` rules if configured
- the test command for the touched modules
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Copilot instructions for React 19 TypeScript components that forward native props, use effects only for synchronization and are tested by role.
Copilot
general
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A TypeScript library repository uses these Copilot instructions while a developer adds an exported utility and asks whether to tighten tsconfig.
Add an exported paginate(items, size) helper to src/array.ts with documentation, and tell me what would break if we turned on noUncheckedIndexedAccess.
Illustrative; not a recorded model run. A generic paginate<T>(items: readonly T[], size: number): T[][] with a TSDoc block describing parameters, return value, the RangeError and a correct @example; no any or non-null assertions; and an explanation that enabling noUncheckedIndexedAccess makes indexed reads T | undefined, proposed as a separate change with an error count rather than mixed into this one.
GitHub Copilot reads repository-wide custom instructions from .github/copilot-instructions.md and path-specific instructions from .github/instructions/*.instructions.md files with an applyTo glob. Copilot can also use AGENTS.md files, where the nearest file in the directory tree takes precedence. Which file types are honored depends on the surface: VS Code, Visual Studio, JetBrains, Xcode, Eclipse and GitHub.com differ.
.github/instructions/github-copilot-typescript.instructions.mdStarting point, not a tested configuration for your repository. Used for files matching applyTo on surfaces that support path-specific instructions. Review the instructions, adapt the file paths and run your project's existing checks.
---
applyTo: "**/*"
---
# TypeScript Project Instructions
Applies to: TypeScript configuration, public module APIs and their documentation in this repository.
Version baseline: checked against TypeScript 5.9 and the TSConfig reference. Read `tsconfig.json` and `package.json` first; do not change compiler options unless the task asks for it.
## Compiler settings
Recommended strictness for new projects (keep the project's existing values otherwise):
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true
}
}
```
- `noUncheckedIndexedAccess` makes `arr[i]` and `record[key]` return `T | undefined`; handle the `undefined` case instead of adding `!`.
- `exactOptionalPropertyTypes` makes `{ name?: string }` reject an explicit `name: undefined`; write `name?: string | undefined` when callers really pass `undefined`.
- Turning on a flag in an existing codebase is its own change: report the error count and fix files in a separate step.
## Type safety
- No `any` in new code. Use `unknown` for untrusted values and narrow it.
- No non-null `!` or `as` casts to silence errors; if one is unavoidable, add a comment with the reason.
- No `@ts-ignore`; use `@ts-expect-error` with a reason, so the comment fails once it is no longer needed.
## Modules and imports
- With `verbatimModuleSyntax`, import types with `import type { User } from './user'`.
- Export only what other modules use; keep helpers file-local.
- Avoid barrel files (`index.ts` that re-exports everything) in application code when they create import cycles or slow builds; follow the project's existing convention.
- Follow the project's module system (`"type": "module"`, file extensions in relative imports when `moduleResolution` is `NodeNext`).
## Documenting public APIs (TSDoc/JSDoc)
Document exported functions, classes and types that other modules or packages consume. Describe behavior, units, errors and edge cases; do not repeat the types.
```ts
/**
* Splits `items` into pages of `size` elements.
*
* @param items - Items in display order. Not modified.
* @param size - Page size; must be a positive integer.
* @returns One array per page; the last page may be shorter.
* @throws RangeError if `size` is not a positive integer.
*
* @example
* paginate([1, 2, 3], 2); // [[1, 2], [3]]
*/
export function paginate<T>(items: readonly T[], size: number): T[][] {
if (!Number.isInteger(size) || size <= 0) {
throw new RangeError('size must be a positive integer');
}
const pages: T[][] = [];
for (let i = 0; i < items.length; i += size) {
pages.push(items.slice(i, i + size));
}
return pages;
}
```
- Keep `@example` blocks runnable and correct; update them when behavior changes.
- Mark deprecated APIs with `@deprecated` and name the replacement.
## Verify before finishing
Run these when they are available in the project:
- `npx tsc --noEmit` (or the project's `typecheck` script)
- the linter (`npx eslint .`), including `@typescript-eslint` rules if configured
- the test command for the touched modules
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Instruction support differs by surface: VS Code supports repository-wide, path-specific and AGENTS.md instructions; Visual Studio supports repository-wide and path-specific; JetBrains and Xcode use .github/copilot-instructions.md. GitHub's documentation describes AGENTS.md files stored anywhere in the repository, with the nearest file in the directory tree taking precedence, or alternatively a single CLAUDE.md or GEMINI.md in the root. Support differs by surface; GitHub's IDE page lists AGENTS.md among the instruction types for VS Code.
Documentation checked 2026-11-05: GitHub Docs: Adding repository custom instructionsGitHub Docs: Repository instructions in your IDE
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Copilot instructions for React 19 TypeScript components that forward native props, use effects only for synchronization and are tested by role.