#Mapping vscode's extension api

2 messages · Page 1 of 1 (latest)

split inlet
#

Let's say I'm writing extension for vscode called extension a
That extension uses extension b's api. extension b is written in typescript, but doesn't really publish any sort of type declaration. But the interfaces are available in source code.
Generally, extension a will get extension b's api by doing something like vscode.extensions.getExtension<ExtensionB>("nameOfExtensionB");
Two questions:

  1. getExtension working like that is risky, I can probably mismatch extension name and interfaces and nothing will tell me I'm doing something wrong, I'd like it to be type safe.
  2. The actual type returned by the extension is CSharpExtensionExports | OmnisharpExtensionExports | LimitedExtensionExports | null. However, I have completely no use for OmnisharpExtensionExports. Also there is no base interface, this is not a good candidate for a DU because there is no discriminator. But I can't just remove OmnisharpExtensionExports from the union as it might in theory really be returned, even though I don't care about it. This wouldn't be a problem if type declarations were provided by a package, but they are not. What to do?
#

I have these interfaces defined, currently OmnisharpExtensionExports is defined minimally. I also have a type guard for the only branch I actually care about.