diff --git a/integration/avoid-import-conflicts/simple.bin b/integration/avoid-import-conflicts/simple.bin index 45366f7ff..aa18fec38 100644 Binary files a/integration/avoid-import-conflicts/simple.bin and b/integration/avoid-import-conflicts/simple.bin differ diff --git a/integration/avoid-import-conflicts/simple.proto b/integration/avoid-import-conflicts/simple.proto index bd0886204..4cc37d287 100644 --- a/integration/avoid-import-conflicts/simple.proto +++ b/integration/avoid-import-conflicts/simple.proto @@ -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; diff --git a/integration/avoid-import-conflicts/simple.ts b/integration/avoid-import-conflicts/simple.ts index 53fa95643..0fd6d0e70 100644 --- a/integration/avoid-import-conflicts/simple.ts +++ b/integration/avoid-import-conflicts/simple.ts @@ -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>>(base?: I): DifferentSimple { + return DifferentSimple.fromPartial(base ?? ({} as any)); + }, + fromPartial, 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 }; } diff --git a/src/main.ts b/src/main.ts index 8efce8ac2..769354ee2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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}, `); });