Dynamic Configuration
TypeScript
Section titled “TypeScript”Instead of a JSON file, you can use a JavaScript or TypeScript file for a dynamic configuration and type annotations:
import type { KnipConfig } from 'knip';
const config: KnipConfig = { entry: ['src/index.ts'], project: ['src/**/*.ts'],};
export default config;/** @type {import('knip').KnipConfig} */const config = { entry: ['src/index.ts'], project: ['src/**/*.ts'],};
export default config;Function
Section titled “Function”You can export a regular or async function that returns the configuration object as well:
import type { KnipConfig } from 'knip';
const config: KnipConfig = async () => { const items = await fetchRepoInfo();
return { entry: ['src/index.ts', ...items], project: ['src/**/*.ts'], };};
export default config;const config = async () => ({ entry: ['src/index.ts'], project: ['src/**/*.ts'],});
export default config;defineConfig
Section titled “defineConfig”Knip also exports a defineConfig helper. It returns the configuration
unchanged, so its only purpose is to type what you pass in:
import { defineConfig } from 'knip/config';
export default defineConfig({ entry: ['src/index.ts'], project: ['src/**/*.ts'],});The same works in a JavaScript configuration file, without the JSDoc annotation. A function is accepted as well:
import { defineConfig } from 'knip/config';
export default defineConfig(async () => ({ entry: ['src/index.ts', ...(await fetchRepoInfo())], project: ['src/**/*.ts'],}));ISC License © 2026Lars Kappert