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
Allow dynamic property access with consistent types.
interface StringDictionary {
[key: string]: string;
}
const dict: StringDictionary = {
name: 'John',
role: 'Developer'
};
console.log(dict['name']); // ✅ string
console.log(dict['anything']); // ✅ string (might be undefined at runtime!)interface NumberArray {
[index: number]: string;
}
const arr: NumberArray = ['a', 'b', 'c'];
console.log(arr[0]); // ✅ stringinterface Config {
name: string;
version: number;
[key: string]: string | number; // Known properties must match
}
const config: Config = {
name: 'app',
version: 1,
author: 'John', // ✅ Additional properties allowed
year: 2024
};Rule: Known property types must be assignable to the index signature type.
interface Getters {
[K: `get${string}`]: () => any;
}
const obj: Getters = {
getName: () => 'John',
getAge: () => 30,
// setName: () => {} // ❌ Error: must start with 'get'
};// Shorthand for index signature
type StringMap = Record<string, string>;
// With specific keys
type Roles = Record<'admin' | 'user' | 'guest', string[]>;
const permissions: Roles = {
admin: ['read', 'write', 'delete'],
user: ['read', 'write'],
guest: ['read']
};// Only specific keys allowed
type AllowedKeys = 'name' | 'age' | 'email';
type UserData = Record<AllowedKeys, string>;
const user: UserData = {
name: 'John',
age: '30',
email: 'john@example.com'
// role: 'admin' // ❌ Error: role not in AllowedKeys
};type Optional<T> = {
[K in keyof T]?: T[K];
};
type WithDefaults<T> = {
[K in keyof T]: T[K] | null;
};
interface User {
name: string;
age: number;
}
type PartialUser = Optional<User>;
// { name?: string; age?: number; }
type NullableUser = WithDefaults<User>;
// { name: string | null; age: number | null; }Stricter type checking for index access:
// tsconfig.json
{
"compilerOptions": {
"noUncheckedIndexedAccess": true
}
}
interface Dict {
[key: string]: string;
}
const dict: Dict = { name: 'John' };
const value = dict['anything']; // Type: string | undefined (safer!)interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'test';
[key: string]: string | undefined;
}
declare const process: {
env: ProcessEnv;
};interface ApiResponse<T> {
status: number;
data: T;
[key: string]: unknown; // Additional metadata
}interface AppConfig {
[section: string]: {
[key: string]: string | number | boolean;
};
}
const config: AppConfig = {
database: {
host: 'localhost',
port: 5432
},
cache: {
enabled: true,
ttl: 3600
}
};any defeats type safetyInstall with Tessl CLI
npx tessl i pantheon-ai/typescript-advanced@0.1.1references