Skip to content

Migrate from Flow to TypeScript#669

Merged
lydell merged 14 commits into
masterfrom
typescript-jsdoc
Jul 12, 2026
Merged

Migrate from Flow to TypeScript#669
lydell merged 14 commits into
masterfrom
typescript-jsdoc

Conversation

@lydell

@lydell lydell commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

This PR gets rid of Flow and switches to TypeScript. This should make it easier to work on the code base, since TypeScript has much better tooling support. It also let us get rid of an annoying Flow+Prettier workaround for type aliases.

I went with JSDoc instead of .ts files, since it was easier, and preserves all workflows in the repo (the code stays valid standard JS) – even with Flow we used their comment syntax instead of their own type annotation syntax.

While this kind of task is pretty well suited to LLM:s, I made this PR without any usage of LLM:s. Some of the boring translations were done by this script I threw together:

import fs from 'node:fs';

function convert(code) {
  return code.replace(
    /((?:\/\/.*\n)*)^(async )?function (\w+)(?:\/\*:: <(\w+)> \*\/)?\(([^()]+)\)\s*(?:\/\*:([^*]+)\*\/\s*)?\{/gm,
    (
      _match,
      comment,
      async_ = '',
      name,
      generics,
      args,
      return_ = ' TODO '
    ) => {
      const types = args.split(/\*\/,\s*/).map((s) => {
        const [param, type = 'TODO'] = s.split(' /*: ');
        return `@param { ${type.trim().replace(/ \*\//, '')} } ${param.trim()}`;
      });
      const argsOnly = args.replace(/\/\*[^*]*\*\//g, '').trim();
      return `
/**${
        comment.length > 0
          ? '\n * ' +
            comment
              .split('\n')
              .map((line) => line.replace(/^\/\/\s*/, ''))
              .join('\n * ')
          : ''
      }${generics ? 'TODO generics: ' + generics : ''}
 * ${types.join('\n * ')}
 * @returns {${return_}}
 */
${async_}function ${name}(${argsOnly}) {
`.trim();
    }
  );
}

for (const fileName of fs.readdirSync('lib')) {
  const file = `lib/${fileName}`;
  const code = fs.readFileSync(file, 'utf8');
  const newCode = convert(code);
  fs.writeFileSync(file, newCode);
}

@lydell lydell merged commit e22f980 into master Jul 12, 2026
42 of 45 checks passed
@lydell lydell deleted the typescript-jsdoc branch July 12, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant