Skip to content

Commit

Permalink
Update version and improve createPicker property handling
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
HichemTab-tech committed Dec 15, 2024
1 parent 1fb455c commit 524ddb8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
".": {
Expand Down
18 changes: 15 additions & 3 deletions src/ts-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyInterface>()` with runtime implementation
call.replaceWithText(`(_obj) => {
Expand Down

0 comments on commit 524ddb8

Please sign in to comment.