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
Recursive utility types for nested objects.
type DeepReadonly<T> = {
readonly [K in keyof T]: T[K] extends object
? T[K] extends Function
? T[K]
: DeepReadonly<T[K]>
: T[K];
};
interface Config {
server: {
host: string;
port: number;
ssl: {
enabled: boolean;
cert: string;
};
};
database: {
host: string;
credentials: {
username: string;
password: string;
};
};
}
type ReadonlyConfig = DeepReadonly<Config>;
const config: ReadonlyConfig = {
server: {
host: 'localhost',
port: 3000,
ssl: {
enabled: true,
cert: '/path/to/cert'
}
},
database: {
host: 'localhost',
credentials: {
username: 'user',
password: 'pass'
}
}
};
// config.server.port = 4000; // ✗ Error: readonly
// config.server.ssl.enabled = false; // ✗ Error: readonly
// config.database.credentials.password = 'new'; // ✗ Error: readonlytype DeepPartial<T> = {
[K in keyof T]?: T[K] extends object
? T[K] extends Function
? T[K]
: DeepPartial<T[K]>
: T[K];
};
function updateConfig(
config: Config,
updates: DeepPartial<Config>
): Config {
return {
...config,
...updates,
server: { ...config.server, ...updates.server },
database: { ...config.database, ...updates.database }
};
}
// Usage - all fields optional at all levels
const updated = updateConfig(config, {
server: {
port: 4000,
ssl: {
enabled: false
}
}
}); // ✓type DeepRequired<T> = {
[K in keyof T]-?: T[K] extends object
? T[K] extends Function
? T[K]
: DeepRequired<T[K]>
: T[K];
};
interface PartialConfig {
server?: {
host?: string;
port?: number;
};
database?: {
host?: string;
};
}
type CompleteConfig = DeepRequired<PartialConfig>;
// All nested fields are now requiredtype DeepMutable<T> = {
-readonly [K in keyof T]: T[K] extends object
? T[K] extends Function
? T[K]
: DeepMutable<T[K]>
: T[K];
};
type MutableConfig = DeepMutable<ReadonlyConfig>;
const mutable: MutableConfig = { /* ... */ };
mutable.server.port = 4000; // ✓ Now allowedfunction deepFreeze<T extends object>(obj: T): DeepReadonly<T> {
Object.freeze(obj);
Object.keys(obj).forEach(key => {
const value = obj[key as keyof T];
if (typeof value === 'object' && value !== null && !Object.isFrozen(value)) {
deepFreeze(value);
}
});
return obj as DeepReadonly<T>;
}
// Usage
const frozen = deepFreeze(config);
// frozen.server.port = 4000; // ✗ Runtime errortype DeepReadonlyArray<T> = {
readonly [K in keyof T]: T[K] extends object
? T[K] extends (infer U)[]
? ReadonlyArray<DeepReadonly<U>>
: DeepReadonly<T[K]>
: T[K];
};
interface DataWithArrays {
items: Array<{
id: number;
tags: string[];
}>;
}
type ReadonlyData = DeepReadonlyArray<DataWithArrays>;
// items is ReadonlyArray<{ readonly id: number; readonly tags: ReadonlyArray<string> }>type DeepReadonlyWithCollections<T> = {
readonly [K in keyof T]: T[K] extends Map<infer K, infer V>
? ReadonlyMap<K, DeepReadonly<V>>
: T[K] extends Set<infer U>
? ReadonlySet<DeepReadonly<U>>
: T[K] extends object
? DeepReadonly<T[K]>
: T[K];
};Install with Tessl CLI
npx tessl i pantheon-ai/typescript-advancedreferences