🔥 How good is Your TypeScript? 5 pro tips to become a rockstar of TypeScript.

Maks Smagin
5 min readFeb 19, 2023

I’m sharing 5 great tips which will help you to improve your TypeScript, even if you have couple of years of experience in it.

1. Stop using any

Avoid using any or code which returns any as much as you can. Any literally disables type-checking. If your stop using it, it will make your types much more reliable, and you as developer will have much more confidence in what your code is doing.

Here’s real world example. I was designing core library for our backend services, and i needed to create configuration service to use it in all our API’s. Core library has it’s own base config with required for each service variables, but service can extend it if needed:

// base config in the core library
const baseConfig = {
name: process.env['npm_package_name'] || '',
version: process.env['npm_package_version'] || '',
port: Number(process.env['APP_PORT']),
host: process.env['APP_HOST'] || '',
env: process.env['NODE_ENV'] || '',
logLevel: process.env['LOG_LEVEL'] || ''
};

type BaseConfig = typeof baseConfig;

// bad
export function extendBaseConfig(
fn: (env: NodeJS.ProcessEnv) => any,
): any {
const localConfig = fn(process.env);
return { ...baseConfig, ...localConfig }; // returns any
}

interface ConfigA extends…

--

--