function ensureTypeScriptValidity () {
  const tsConfigPath = ts.findConfigFile(distRoot, ts.sys.fileExists, 'tsconfig.json')
  if (!tsConfigPath) {
    throw Error(resolvePath('tsconfig.json') + ' not found')
  }
  const { config } = ts.readConfigFile(tsConfigPath, ts.sys.readFile)
  config.compilerOptions.noEmit = true
  const { options, fileNames, errors } = ts.parseJsonConfigFileContent(config, ts.sys, distRoot)

  const program = ts.createProgram({ options, rootNames: fileNames, configFileParsingDiagnostics: errors })
  const emitResult = program.emit()
  const diagnostics = [ ...ts.getPreEmitDiagnostics(program), ...emitResult.diagnostics ]
  if (diagnostics.length === 0) {
    return
  }

  /** @type {ts.FormatDiagnosticsHost} */
  const formatDiagnosticsHost = {
    getCurrentDirectory: ts.sys.getCurrentDirectory,
    getCanonicalFileName: file => file,
    getNewLine: () => ts.sys.newLine
  }
  const error = new Error(ts.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost))
  error.name = 'TypeScriptError'
  throw error
}
@throws {Error} if TypeScript validation fails