-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Description
I'm migrating all extensions to build using esbuild instead of webpack. One of the last remaining extension is git. This migration is blocked by its use of const enums evanw/esbuild#4394
Problem
The git.d.ts api file declares the git extension's api. This file defines both pure types as well as a few const enums
In the git extension, the g.d.ts file is imported in a number of other files like this:
import { API, RefType, Repository } from './typings/git';Because there is only a d.ts file and no actual code file, ESBuild requires that you add a type modifier to these imports:
import type { API, RefType, Repository } from './typings/git';However the const enums RefType is used at runtime in many places (for example in code such as b.type === RefType.RemoteHead) so we can't actually add the type modifier to the import
Proposal
After a few experiments, here's what I think may work:
- In the git extension, add a new file called
git.constants.tsthat provides runtime declarations of all the const enums fromgit.d.ts.:
import type * as gitApi from './typings/git.js';
export const RefType = Object.freeze({
Head: 0,
RemoteHead: 1,
Tag: 2
}) satisfies typeof gitApi.RefType;I think these types should compatible now in any place that expects a RefType at runtime
-
In the git extension, update all imports of
git.d.tsto use import type -
In the git extension, for any places that need the const enums value at runtime, import from
git.constants.d.tsinstead
@lszomoru Let me know if this plan sounds good or if you have ideas on simpler ways to handle this
cc @jrieken