From 524ddb8973b0a22abe03ede6f101148ab5242bb0 Mon Sep 17 00:00:00 2001 From: HichemTab Date: Sun, 15 Dec 2024 21:08:52 +0100 Subject: [PATCH] Update version and improve `createPicker` property handling - Bumped package version from 1.0.2 to 1.0.3 in `package.json` and `package-lock.json`. - Enhanced `createPicker` logic in `ts-transformer.ts`: - Switched to `TypeChecker` to resolve all interface properties, including inherited ones. - Improved error handling for unresolved type information. --- package-lock.json | 4 ++-- package.json | 2 +- src/ts-transformer.ts | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b9487e7..7b25dd2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ts-runtime-picker", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ts-runtime-picker", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "dependencies": { "ts-morph": "^24.0.0" diff --git a/package.json b/package.json index 4592e7c..159c92f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-runtime-picker", - "version": "1.0.2", + "version": "1.0.3", "main": "dist/index.js", "types": "dist/index.d.ts", ".": { diff --git a/src/ts-transformer.ts b/src/ts-transformer.ts index 9ccea7a..a7c897e 100644 --- a/src/ts-transformer.ts +++ b/src/ts-transformer.ts @@ -37,14 +37,26 @@ export function transform(code: string, filePath: string): string { const typeArg = call.getTypeArguments()[0]; const typeName = typeArg.getText(); - // Get the type declaration for the interface + // Get the interface declaration const interfaceDecl = sourceFile.getInterface(typeName); + if (!interfaceDecl) { throw new Error(`Interface ${typeName} not found in ${filePath}`); } - // Extract keys from the interface - const keys = interfaceDecl.getProperties().map(prop => `"${prop.getName()}"`); + // Use TypeChecker to resolve all properties, including inherited ones + const typeChecker = project.getTypeChecker(); + const type = typeChecker.getTypeAtLocation(interfaceDecl); + + if (!type) { + throw new Error(`Type information for ${typeName} could not be resolved.`); + } + + // Get all properties, including inherited ones + const properties = type.getProperties(); + + // Extract property names + const keys = properties.map(prop => `"${prop.getName()}"`); // Replace `createPicker()` with runtime implementation call.replaceWithText(`(_obj) => {