Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: stephenh/ts-proto
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.156.5
Choose a base ref
...
head repository: stephenh/ts-proto
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.156.6
Choose a head ref
  • 2 commits
  • 6 files changed
  • 2 contributors

Commits on Aug 16, 2023

  1. fix: use correct imports for optional fields (#904)

    It seems that the ts-poet.Code.toString() changes the struct and it was causing
    the code gen to fail to use the correct imports in some situations.
    
    Added a struct which was failing to compile before the fix.
    andrehp authored Aug 16, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fa13ec7 View commit details
  2. chore(release): 1.156.6 [skip ci]

    ## [1.156.6](v1.156.5...v1.156.6) (2023-08-16)
    
    ### Bug Fixes
    
    * use correct imports for optional fields ([#904](#904)) ([fa13ec7](fa13ec7))
    semantic-release-bot committed Aug 16, 2023
    Copy the full SHA
    26fad31 View commit details
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.156.6](https://github.com/stephenh/ts-proto/compare/v1.156.5...v1.156.6) (2023-08-16)


### Bug Fixes

* use correct imports for optional fields ([#904](https://github.com/stephenh/ts-proto/issues/904)) ([fa13ec7](https://github.com/stephenh/ts-proto/commit/fa13ec752c6564af045081548f5fc5cabb687151))

## [1.156.5](https://github.com/stephenh/ts-proto/compare/v1.156.4...v1.156.5) (2023-08-15)


Binary file modified integration/avoid-import-conflicts/simple.bin
Binary file not shown.
5 changes: 5 additions & 0 deletions integration/avoid-import-conflicts/simple.proto
Original file line number Diff line number Diff line change
@@ -13,6 +13,11 @@ message Simple {
simple2.Simple otherSimple = 2;
}

message DifferentSimple {
string name = 1;
optional simple2.Simple otherOptionalSimple2 = 2;
}

message SimpleEnums {
SimpleEnum local_enum = 1;
simple2.SimpleEnum import_enum = 2;
83 changes: 83 additions & 0 deletions integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
@@ -56,6 +56,11 @@ export interface Simple {
otherSimple: Simple3 | undefined;
}

export interface DifferentSimple {
name: string;
otherOptionalSimple2?: Simple3 | undefined;
}

export interface SimpleEnums {
localEnum: SimpleEnum;
importEnum: SimpleEnum1;
@@ -145,6 +150,84 @@ export const Simple = {
},
};

function createBaseDifferentSimple(): DifferentSimple {
return { name: "", otherOptionalSimple2: undefined };
}

export const DifferentSimple = {
encode(message: DifferentSimple, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.name !== "") {
writer.uint32(10).string(message.name);
}
if (message.otherOptionalSimple2 !== undefined) {
Simple3.encode(message.otherOptionalSimple2, writer.uint32(18).fork()).ldelim();
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): DifferentSimple {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseDifferentSimple();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}

message.name = reader.string();
continue;
case 2:
if (tag !== 18) {
break;
}

message.otherOptionalSimple2 = Simple3.decode(reader, reader.uint32());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},

fromJSON(object: any): DifferentSimple {
return {
name: isSet(object.name) ? String(object.name) : "",
otherOptionalSimple2: isSet(object.otherOptionalSimple2)
? Simple3.fromJSON(object.otherOptionalSimple2)
: undefined,
};
},

toJSON(message: DifferentSimple): unknown {
const obj: any = {};
if (message.name !== "") {
obj.name = message.name;
}
if (message.otherOptionalSimple2 !== undefined) {
obj.otherOptionalSimple2 = Simple3.toJSON(message.otherOptionalSimple2);
}
return obj;
},

create<I extends Exact<DeepPartial<DifferentSimple>, I>>(base?: I): DifferentSimple {
return DifferentSimple.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<DifferentSimple>, I>>(object: I): DifferentSimple {
const message = createBaseDifferentSimple();
message.name = object.name ?? "";
message.otherOptionalSimple2 = (object.otherOptionalSimple2 !== undefined && object.otherOptionalSimple2 !== null)
? Simple3.fromPartial(object.otherOptionalSimple2)
: undefined;
return message;
},
};

function createBaseSimpleEnums(): SimpleEnums {
return { localEnum: 0, importEnum: 0 };
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-proto",
"version": "1.156.5",
"version": "1.156.6",
"description": "",
"main": "build/plugin.js",
"repository": "github:stephenh/ts-proto",
3 changes: 0 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -873,9 +873,6 @@ function generateInterfaceDeclaration(
const name = maybeSnakeToCamel(fieldDesc.name, options);
const isOptional = isOptionalProperty(fieldDesc, messageDesc.options, options);
const type = toTypeName(ctx, messageDesc, fieldDesc, isOptional);
if (isOptional && !type.toString().includes("undefined")) {
console.warn(name, type);
}
chunks.push(code`${maybeReadonly(options)}${name}${isOptional ? "?" : ""}: ${type}, `);
});