AgentSkillsCN

typescript-imports

当您需要编写 TypeScript 导入语句时,此技能将重点指导导入顺序、分组方式,以及类型导入的最佳实践。

SKILL.md
--- frontmatter
name: typescript-imports
description: Use when writing TypeScript imports - covers ordering, grouping, and type imports

TypeScript Imports

Rules

  1. Type imports first: import type before value imports
  2. Separate type imports: Never mix types and values in one import
  3. Group ordering: builtin → external → internal → relative
  4. Blank lines between groups
  5. Alphabetical within groups

Example

typescript
// 1. Type imports (by group)
import type { TestContext } from 'bun:test';

import type { InferSelectModel } from 'drizzle-orm';

import type { Result } from '@company/monads';

import type { User } from '../types';

// 2. Value imports (by group)
import { describe, expect, it } from 'bun:test';

import { eq } from 'drizzle-orm';
import { z } from 'zod';

import { Ok, Err } from '@company/monads';
import { logger } from '@company/logger';

import { calculateCost } from '../calculation';
import { validateInput } from './validator';

Group Order

PriorityGroupExamples
1Builtinbun:test, node:fs
2Externalzod, drizzle-orm
3Internal@company/*
4Relative../, ./

Auto-fix

Most violations auto-fix with bun run lint --fix or eslint --fix.

Manual fixes needed for:

  • Circular dependencies
  • Choosing named vs default imports