Skip to content

Commit

Permalink
set interface name instead of renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed Jun 13, 2024
1 parent f62b359 commit 221595f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-foxes-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tsxmod/utils": patch
---

Set the name of the specific interface instead of renaming all call sites in `addComputedTypes`.
7 changes: 6 additions & 1 deletion packages/utils/src/types/addComputedTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ describe('addComputedTypes', () => {
'test.ts',
`interface InterfaceA { a: number; }
interface InterfaceB extends InterfaceA { b: number; }
const createSource = <T>(source: T) => source;
const source = createSource<InterfaceB>({ a: 1, b: 2 });
`,
{ overwrite: true }
)
Expand All @@ -65,9 +67,12 @@ describe('addComputedTypes', () => {
type InterfaceA = Compute<_InterfaceA>;
interface _InterfaceB extends _InterfaceA { b: number; }
interface _InterfaceB extends InterfaceA { b: number; }
type InterfaceB = Compute<_InterfaceB>;
const createSource = <T>(source: T) => source;
const source = createSource<InterfaceB>({ a: 1, b: 2 });
"
`)

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/types/addComputedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function addComputedTypes(sourceFile: SourceFile) {
const originalInterfaceName = interfaceDeclaration.getName()
const interfaceName = `_${originalInterfaceName}`

interfaceDeclaration.rename(interfaceName)
interfaceDeclaration.getNameNode().replaceWithText(interfaceName)

sourceFile.insertTypeAlias(interfaceDeclaration.getChildIndex() + 1, {
name: originalInterfaceName,
Expand Down

0 comments on commit 221595f

Please sign in to comment.