#64464·TypeScript

在完成清洁构建后的第一次增量重建速度比全面检查慢 75 倍

作者: resure创建于 2026年9月26日更新于 2026年9月28日
标签Needs Investigation

// generate.js — node generate.js [leaves=6000] [types=3000] const fs = require('fs'); const path = require('path');

const dir = path.resolve(process.argv[2] || 'repro'); const LEAVES = Number(process.argv[3] || 6000); const TYPES = Number(process.argv[4] || 3000);

fs.rmSync(path.join(dir, 'src'), {recursive: true, force: true}); fs.mkdirSync(path.join(dir, 'src/types'), {recursive: true}); fs.mkdirSync(path.join(dir, 'src/leaves'), {recursive: true}); const write = (file, text) => fs.writeFileSync(path.join(dir, 'src', file), text);

write('hub.ts', 'export const HUB_PREFIX = "hub";\nexport const HUB_LIMIT = 10;\n'); for (let i = 0; i < TYPES; i++) { write(types/t${i}.ts, export interface Model${i} { id: string; value${i}: number; }\n + export function make${i}(id: string): Model${i} { return {id, value${i}: ${i}}; }\n); } write('types/index.ts', Array.from({length: TYPES}, (, i) => export {make${i}} from './t${i}';\n).join('')); for (let i = 0; i < LEAVES; i++) { const a = i % TYPES; const b = (i * 7 + 3) % TYPES; write(leaves/l${i}.ts, import {HUB_PREFIX} from '../hub';\n + import {make${a}, make${b}} from '../types';\n + export const leaf${i} = {first: make${a}(HUB_PREFIX), second: make${b}('${i}')};\n); } write('index.ts', Array.from({length: LEAVES}, (, i) => export * from './leaves/l${i}';\n).join('')); fs.writeFileSync(path.join(dir, 'tsconfig.json'), JSON.stringify({ compilerOptions: { target: 'es2022', module: 'esnext', moduleResolution: 'bundler', strict: true, noEmit: true, incremental: true, skipLibCheck: true, }, include: ['src'], }, null, 2));

内容来源: microsoft/TypeScript