Comprehensive TypeScript guidance covering compiler configuration, advanced types, utility types, type guards, strict mode workflows, and documentation patterns; use when configuring tsconfig, designing complex generics, making illegal states unrepresentable, fixing type errors, or writing testable and maintainable type-safe APIs.
Overall
score
99%
Does it follow best practices?
Validation for skill structure
"strict": true enables all strict type checking options. It's the foundation of type-safe TypeScript.
strict)noImplicitAny - Disallow implicit any types
// Error with noImplicitAny
function greet(name) { // Parameter 'name' implicitly has an 'any' type
console.log(`Hello, ${name}`);
}
// Fix: Add explicit type
function greet(name: string) {
console.log(`Hello, ${name}`);
}strictNullChecks - null and undefined require explicit handling
// Error with strictNullChecks
function getLength(str: string | null) {
return str.length; // Object is possibly 'null'
}
// Fix: Check for null
function getLength(str: string | null) {
return str?.length ?? 0;
}strictFunctionTypes - Stricter checking of function parameter types
type Handler = (value: string) => void;
type GenericHandler = (value: string | number) => void;
// Error: Type 'GenericHandler' is not assignable to 'Handler'
const handler: Handler = (value: string | number) => {};strictBindCallApply - Check bind, call, and apply arguments
function greet(name: string, age: number) {
console.log(`${name} is ${age} years old`);
}
greet.call(undefined, "Alice", "30"); // Error: Argument of type 'string' not assignable to 'number'strictPropertyInitialization - Ensure class properties are initialized
class User {
name: string; // Error: Property 'name' has no initializer
age: number = 0; // OK: Has initializer
email!: string; // OK: Definite assignment assertion
constructor() {
this.name = ""; // OK: Initialized in constructor
}
}noImplicitThis - Disallow implicit any for this
// Error with noImplicitThis
const obj = {
name: "Alice",
greet() {
return function() {
console.log(this.name); // 'this' implicitly has type 'any'
};
}
};
// Fix: Use arrow function
const obj = {
name: "Alice",
greet() {
return () => {
console.log(this.name); // OK: Arrow function captures 'this'
};
}
};alwaysStrict - Emit "use strict" in generated JavaScript
noUnusedLocals - Error on unused local variables
function calculate() {
const x = 10; // Error: 'x' is declared but never used
return 5;
}noUnusedParameters - Error on unused function parameters
function greet(name: string, age: number) { // Error: 'age' is declared but never used
console.log(`Hello, ${name}`);
}
// Fix: Prefix with underscore
function greet(name: string, _age: number) {
console.log(`Hello, ${name}`);
}noImplicitReturns - Error if not all code paths return a value
function getStatus(value: number): string {
if (value > 0) {
return "positive";
}
// Error: Not all code paths return a value
}
// Fix: Handle all paths
function getStatus(value: number): string {
if (value > 0) {
return "positive";
}
return "non-positive";
}noFallthroughCasesInSwitch - Error on switch fallthrough
function getDay(day: number): string {
switch (day) {
case 0:
return "Sunday";
case 1: // Error: Fallthrough case in switch
console.log("Monday");
case 2:
return "Tuesday";
}
return "Unknown";
}noUncheckedIndexedAccess - Index signatures return T | undefined
const colors: Record<string, string> = { red: "#ff0000" };
// Without noUncheckedIndexedAccess
const red = colors["red"]; // Type: string
// With noUncheckedIndexedAccess
const red = colors["red"]; // Type: string | undefined
if (red) {
console.log(red.toUpperCase()); // Safe
}exactOptionalPropertyTypes - Distinguish undefined from missing
interface Config {
timeout?: number;
}
// Without exactOptionalPropertyTypes
const config: Config = { timeout: undefined }; // OK
// With exactOptionalPropertyTypes
const config: Config = { timeout: undefined }; // Error
const config: Config = {}; // OKEnabling strict mode in an existing codebase:
{
"compilerOptions": {
"noImplicitAny": true,
// Fix errors, then enable next flag
"strictNullChecks": true,
// Continue until all strict flags enabled
}
}@ts-expect-error for temporary suppression// @ts-expect-error TODO: Fix null handling
const value = maybeNull.property;Fix by priority
Use strictNullChecks migration helpers
// Option 1: Non-null assertion (use sparingly)
const value = maybeNull!.property;
// Option 2: Optional chaining
const value = maybeNull?.property;
// Option 3: Nullish coalescing
const value = maybeNull ?? defaultValue;"strict": truestrict but highly recommendedunknown over any - Forces type checking! assertions - Prefer explicit null checksas any to bypass errors - Defeats purpose of strict mode! assertions - Hides potential null errorsInstall with Tessl CLI
npx tessl i pantheon-ai/typescript-advancedreferences