Skip to content

Commit

Permalink
fix: resolve import collisions for interfaces (#300)
Browse files Browse the repository at this point in the history
Fixes #298
  • Loading branch information
doochik committed May 18, 2021
1 parent ee656c8 commit 773d866
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 1 deletion.
@@ -0,0 +1 @@
outputJsonMethods=false,outputEncodeMethods=false,outputClientImpl=false,nestJs=false
13 changes: 13 additions & 0 deletions integration/avoid-import-conflicts-types-only/simple-test.ts
@@ -0,0 +1,13 @@
import { Simple } from './simple';

describe('Simple', () => {
it('type checking works correctly', () => {
const simple: Simple = {
name: 'foo',
otherSimple: {
simple2Name: 'bar',
simple2Age: 1,
},
}
});
})
Binary file not shown.
8 changes: 8 additions & 0 deletions integration/avoid-import-conflicts-types-only/simple.proto
@@ -0,0 +1,8 @@
syntax = "proto3";
package simple;
import "simple2.proto";

message Simple {
string name = 1;
simple2.Simple otherSimple = 2;
}
9 changes: 9 additions & 0 deletions integration/avoid-import-conflicts-types-only/simple.ts
@@ -0,0 +1,9 @@
/* eslint-disable */
import { Simple as Simple1 } from './simple2';

export const protobufPackage = 'simple';

export interface Simple {
name: string;
otherSimple: Simple1 | undefined;
}
Binary file not shown.
8 changes: 8 additions & 0 deletions integration/avoid-import-conflicts-types-only/simple2.proto
@@ -0,0 +1,8 @@
syntax = "proto3";
package simple2;

message Simple {
string simple2Name = 1;
int32 simple2Age = 2;
}

7 changes: 7 additions & 0 deletions integration/avoid-import-conflicts-types-only/simple2.ts
@@ -0,0 +1,7 @@
/* eslint-disable */
export const protobufPackage = 'simple2';

export interface Simple {
simple2Name: string;
simple2Age: number;
}
3 changes: 2 additions & 1 deletion src/main.ts
Expand Up @@ -498,7 +498,8 @@ function generateInterfaceDeclaration(
const chunks: Code[] = [];

maybeAddComment(sourceInfo, chunks, messageDesc.options?.deprecated);
chunks.push(code`export interface ${fullName} {`);
// interface name should be defined to avoid import collisions
chunks.push(code`export interface ${def(fullName)} {`);

if (ctx.options.outputTypeRegistry) {
chunks.push(code`$type: '${fullTypeName}',`);
Expand Down

0 comments on commit 773d866

Please sign in to comment.