Skip to content

Commit 83c51ed

Browse files
committed
feat: add new ExtensionMetaData interface for better typings
- Added new `ExtensionMetaData` interface for better typings and vscode intellisense. - Changed the `extensionData` property map to use typing of the new `ExtensionMetaData` interface. - Changed `get` and `getAll` methods to use the typing of `ExtensionMetaData` interface. This is instead of using return type of the old `createExtensionData` method, and still allows vscode intellisense of the data properties. It also is a better way to type the properties.
1 parent b5d1bcb commit 83c51ed

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/extensionData.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import isWsl from "is-wsl";
44
import {IPackageJson} from "package-json-type";
55

66
import {readJsonFile} from "./utils";
7+
import {ExtensionMetaData} from "./interfaces/extensionMetaData";
78

89
export class ExtensionData {
910
/**
1011
* This extension details in the form of a key:value Map object.
1112
*
12-
* @type {Map<string, string>}
13+
* @type {Map<keyof ExtensionMetaData, string>}
1314
*/
14-
private extensionData = new Map<string, string>();
15+
private extensionData = new Map<keyof ExtensionMetaData, string>();
1516

1617
/**
1718
* The package.json data for this extension.
@@ -79,18 +80,18 @@ export class ExtensionData {
7980
*
8081
* @param {K} key The key of the extension detail to get.
8182
*
82-
* @returns {ReturnType<typeof this.createExtensionData>[K] | undefined} The value of the extension detail, or undefined if the key does not exist.
83+
* @returns {ExtensionMetaData[K] | undefined} The value of the extension detail, or undefined if the key does not exist.
8384
*/
84-
public get<K extends keyof ReturnType<typeof this.createExtensionData>>(key: K): ReturnType<typeof this.createExtensionData>[K] | undefined {
85-
return this.extensionData.get(key) as ReturnType<typeof this.createExtensionData>[K] | undefined;
85+
public get<K extends keyof ExtensionMetaData>(key: K): ExtensionMetaData[K] | undefined {
86+
return this.extensionData.get(key) as ExtensionMetaData[K] | undefined;
8687
}
8788

8889
/**
8990
* Get all extension data.
9091
*
91-
* @returns {ReadonlyMap<string, string>} A read-only Map containing all extension details.
92+
* @returns {ReadonlyMap<keyof ExtensionMetaData, string>} A read-only Map containing all extension details.
9293
*/
93-
public getAll(): ReadonlyMap<string, string> {
94+
public getAll(): ReadonlyMap<keyof ExtensionMetaData, string> {
9495
return this.extensionData;
9596
}
9697
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export interface ExtensionMetaData {
2+
id: string;
3+
name: string;
4+
displayName: string;
5+
version: string;
6+
userExtensionsPath: string;
7+
builtInExtensionsPath: string;
8+
9+
/**
10+
* Only set when running in WSL.
11+
*/
12+
13+
WindowsUserExtensionsPathFromWsl?: string;
14+
WindowsBuiltInExtensionsPathFromWsl?: string;
15+
}

0 commit comments

Comments
 (0)