Skip to content

Conversation

@eddeee888
Copy link
Collaborator

Description

This is the continuation of #10508. We merged that PR early to unblock the enum-in-input scenario

Related #10496

Type of change

  • Add tests

How Has This Been Tested?

  • Unit test
@changeset-bot
Copy link

changeset-bot bot commented Nov 27, 2025

⚠️ No Changeset found

Latest commit: 0595dae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines -814 to -865
protected _buildTypeImport(identifier: string, source: string, asDefault = false): string {
const { useTypeImports } = this.config;
if (asDefault) {
if (useTypeImports) {
return `import type { default as ${identifier} } from '${source}';`;
}
return `import ${identifier} from '${source}';`;
}
return `import${useTypeImports ? ' type' : ''} { ${identifier} } from '${source}';`;
}

protected handleEnumValueMapper(
typeIdentifier: string,
importIdentifier: string | null,
sourceIdentifier: string | null,
sourceFile: string | null
): string[] {
if (importIdentifier !== sourceIdentifier) {
// use namespace import to dereference nested enum
// { enumValues: { MyEnum: './my-file#NS.NestedEnum' } }
return [
this._buildTypeImport(importIdentifier || sourceIdentifier, sourceFile),
`import ${typeIdentifier} = ${sourceIdentifier};`,
];
}
if (sourceIdentifier !== typeIdentifier) {
return [this._buildTypeImport(`${sourceIdentifier} as ${typeIdentifier}`, sourceFile)];
}
return [this._buildTypeImport(importIdentifier || sourceIdentifier, sourceFile)];
}

public getEnumsImports(): string[] {
return Object.keys(this.config.enumValues)
.flatMap(enumName => {
const mappedValue = this.config.enumValues[enumName];

if (mappedValue.sourceFile) {
if (mappedValue.isDefault) {
return [this._buildTypeImport(mappedValue.typeIdentifier, mappedValue.sourceFile, true)];
}

return this.handleEnumValueMapper(
mappedValue.typeIdentifier,
mappedValue.importIdentifier,
mappedValue.sourceIdentifier,
mappedValue.sourceFile
);
}

return [];
})
.filter(Boolean);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These utility functions are now abstracted to be shared between base-types-visitor and typescript-operations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants