AI Skill Report Card

Applying TypeScript Coding Standards

A87·Sep 20, 2026·Source: Extension-page
14 / 15

When writing or reviewing TypeScript code, check against these rules in order of priority: 强制 (mandatory) rules must never be violated; 推荐 (recommended) rules should be followed unless there's a documented reason not to.

TypeScript
// Mandatory checks const foo = 'bar' as string; // not <string>'bar' const foo2 = { x: 1 } as MyType; // object literals: use `as`, not <T> class Foo { foo(s: string): void; // overloads adjacent foo(n: number): void; foo(sn: string | number): void {} } type Foo = { name: string; greet(): void }; // `;` delimiter let x: string = 'bar'; // space after colon // Recommended checks interface Point { x: number; y: number } // prefer interface over type for objects const arr: string[] = ['a']; // simple type -> T[] const arr2: Array<{ id: string }> = []; // complex type -> Array<T>
Recommendation
Add a 'bad outcome' example showing a fully non-compliant code block reviewed end-to-end, not just isolated fixes, to reinforce real-world review scenarios.
14 / 15

Progress checklist when reviewing/writing TS code:

  • Confirm underlying JS spec is followed first (this spec only covers TS-specific additions)
  • Check type assertions use as Type, never <Type>, never on object literals (except any/unknown)
  • Check array type style: T[] for primitives, Array<T> for complex/union/object/function types
  • Check interface/type member delimiter is ;, spacing around : and => is correct
  • Check member ordering: static > instance, field > constructor > method, public > protected > private
  • Check overloaded function/method signatures are grouped together
  • Check accessibility modifiers are explicit for non-public members (private/protected)
  • Check no namespace/module used for runtime code (only allowed in declare contexts)
  • Check no require(), prefer ES2015 import
  • Check no redundant type annotations when inference already narrows the type
  • Check // @ts-ignore / // @ts-expect-error always has explanatory comment
  • Check no dangling this alias (const self = this), prefer arrow functions
  • Check + operator operands are both numbers or both strings (no implicit coercion)
  • Check string literals use single quotes
  • Check no triple-slash /// references outside .d.ts files
  • Check empty interfaces are removed/merged
  • Check as const used when value equals a literal type declaration
Recommendation
Include a brief note on how to configure/extend eslint-config-ali/typescript in a project (e.g., .eslintrc snippet) since the skill references it as a best practice.

Mandatory (强制)

RuleESLint rule idSummary
Group overloaded signatures@typescript-eslint/adjacent-overload-signaturesAll overloads of the same function/method must be adjacent
as Type assertions only@typescript-eslint/consistent-type-assertionsNo <Type>x; no assertion on object literals except any
No tslint comments@typescript-eslint/ban-tslint-commentRemove // tslint:... directives (deprecated tool)
Consistent member delimiter@typescript-eslint/member-delimiter-styleUse ; to separate interface/type members
No confusing void type@typescript-eslint/no-invalid-void-typevoid only valid as return type or generic param, not unioned with other types
No namespace for runtime code@typescript-eslint/no-namespaceOnly allowed inside declare blocks
No non-null assertion after optional chaining@typescript-eslint/no-non-null-asserted-optional-chainfoo?.bar! is a type-safety bug
No module keyword@typescript-eslint/prefer-namespace-keywordUse namespace, except declare module
Single quotes@typescript-eslint/quotesString literals use '...'
Matching + operand types@typescript-eslint/restrict-plus-operandsBoth numeric or both string, no mixing
No triple-slash reference@typescript-eslint/triple-slash-referenceOnly allowed in .d.ts files
Type annotation spacing@typescript-eslint/type-annotation-spacingNo space before :, one space after; spaces around =>
Typed interface/type members@typescript-eslint/typedefEvery member must declare its type

Recommended (推荐)

RuleESLint rule idSummary
Array type style@typescript-eslint/array-typeT[] for primitives, Array<T> for complex types
Explain ts-comment directives@typescript-eslint/ban-ts-comment@ts-ignore/@ts-expect-error needs a description
Readonly over literal getter@typescript-eslint/class-literal-property-styleUse readonly field instead of getter returning a literal
Prefer interface over type@typescript-eslint/consistent-type-definitionsFor object shapes, prefer interface
Explicit member accessibility@typescript-eslint/explicit-member-accessibilityMark private/protected explicitly; public can be omitted
Member ordering@typescript-eslint/member-orderingstatic→instance, field→ctor→method, public→protected→private
Method signature as property@typescript-eslint/method-signature-stylefunc: (arg: T) => R instead of func(arg: T): R
No confusing non-null assertion@typescript-eslint/no-confusing-non-null-assertionAvoid ! right before ==/===
No empty interfaces@typescript-eslint/no-empty-interfaceRemove or merge empty/pass-through interfaces
No inferrable types@typescript-eslint/no-inferrable-typesSkip type annotation when default value makes it obvious
ES2015 import over require@typescript-eslint/no-require-importsUse import syntax
No this alias@typescript-eslint/no-this-aliasUse arrow functions instead of const self = this
Prefer as const@typescript-eslint/prefer-as-constWhen value equals its literal type
Prefer union param over overloads@typescript-eslint/unified-signaturesCombine overloads into one signature with union types when only the param type differs
17 / 20

Example 1 — Type assertion: Input:

TypeScript
const x = { name: 'a' } as T; const y = <string>someValue;

Output:

TypeScript
const x: T = { name: 'a' }; // object literal: declare type directly const y = someValue as string; // use `as`, not angle brackets

Example 2 — Array type: Input:

TypeScript
const list: Array<string> = ['a', 'b']; const objs: { id: string }[] = [];

Output:

TypeScript
const list: string[] = ['a', 'b']; // simple type -> T[] const objs: Array<{ id: string }> = []; // complex type -> Array<T>

Example 3 — Member ordering & accessibility: Input:

TypeScript
class Foo { bar = 'bar'; constructor() {} static foo = 'foo'; getBar() {} }

Output:

TypeScript
class Foo { public static foo = 'foo'; protected bar = 'bar'; public constructor() {} public getBar() {} }
Recommendation
Consider trimming the rule reference tables slightly or linking to external docs, since they add length without much unique guidance beyond ESLint rule names already implying behavior.
  • Apply the JavaScript coding spec first; this document only adds TS-specific rules on top.
  • Prefer interface for object/record shapes because it supports extends/implements and gives clearer error messages; use type for unions, intersections, tuples, and mapped types.
  • When suppressing TS errors with directive comments, always explain why — treat it as a TODO marker, not a silence switch.
  • Favor ES module syntax and native language features (as const, optional chaining) over legacy patterns (require, module, self = this).
  • Use eslint-config-ali/typescript (or its sub-paths) to enforce these rules automatically rather than manual review alone.
  • Using <Type>value syntax — conflicts with JSX and is disallowed; always use value as Type.
  • Casting object literals with as when they should be typed directly (const x: T = {...} instead of const x = {...} as T).
  • Mixing namespace/module into regular application code instead of ES modules — only valid in ambient declare contexts.
  • Leaving // @ts-ignore without any explanation — hides real bugs.
  • Declaring redundant types like const foo: number = 1 when inference already resolves it.
  • Splitting overloaded function signatures apart in the file instead of grouping them together.
  • Using foo?.bar! — the non-null assertion after optional chaining defeats the safety of ?. and is almost always a bug.
0
Grade AAI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
14/15
Workflow
14/15
Examples
17/20
Completeness
18/20
Format
14/15
Conciseness
14/15