ts-proto 1.96.1 → 1.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.markdown +5 -1
- package/build/main.js +11 -5
- package/build/options.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.97.0](https://github.com/stephenh/ts-proto/compare/v1.96.1...v1.97.0) (2021-12-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add an option to disable Exact types ([#456](https://github.com/stephenh/ts-proto/issues/456)) ([9c53d7e](https://github.com/stephenh/ts-proto/commit/9c53d7efb0252c7ea0af85a5d161ff94bcd69760))
|
|
7
|
+
|
|
1
8
|
## [1.96.1](https://github.com/stephenh/ts-proto/compare/v1.96.0...v1.96.1) (2021-12-28)
|
|
2
9
|
|
|
3
10
|
|
package/README.markdown
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
> `ts-proto` transforms your `.proto` files into strongly-typed, idiomatic TypeScript files!
|
|
7
7
|
|
|
8
|
-
(Note, if you're a new user of ts-proto and using a modern TS setup with `esModuleInterop`, you need to also pass that as a `ts_proto_opt`.)
|
|
8
|
+
(Note, if you're a new user of ts-proto and using a modern TS setup with `esModuleInterop`, or want to use ts-proto in ESM / snowpack / vite, you need to also pass that as a `ts_proto_opt`.)
|
|
9
9
|
|
|
10
10
|
## Table of contents
|
|
11
11
|
|
|
@@ -350,6 +350,10 @@ Generated code will be placed in the Gradle build directory.
|
|
|
350
350
|
|
|
351
351
|
- With `--ts_proto_opt=enumsAsLiterals=true`, the generated enum types will be enum-ish object with `as const`.
|
|
352
352
|
|
|
353
|
+
- With `--ts_proto_opt=useExactTypes=false`, the generated `fromPartial` method will not use Exact types.
|
|
354
|
+
|
|
355
|
+
The default behavior is `useExactTypes=true`, which makes `fromPartial` use Exact type for its argument to make TypeScript reject any unknown properties.
|
|
356
|
+
|
|
353
357
|
### Only Types
|
|
354
358
|
|
|
355
359
|
If you're looking for `ts-proto` to generate only types for your Protobuf types then passing all three of `outputEncodeMethods`, `outputJsonMethods`, and `outputClientImpl` as `false` is probably what you want, i.e.:
|
package/build/main.js
CHANGED
|
@@ -1101,13 +1101,19 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
1101
1101
|
function generateFromPartial(ctx, fullName, messageDesc) {
|
|
1102
1102
|
const { options, utils, typeMap } = ctx;
|
|
1103
1103
|
const chunks = [];
|
|
1104
|
-
const Timestamp = utils_1.impProto(options, 'google/protobuf/timestamp', 'Timestamp');
|
|
1105
1104
|
// create the basic function declaration
|
|
1106
1105
|
const paramName = messageDesc.field.length > 0 ? 'object' : '_';
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1106
|
+
if (ctx.options.useExactTypes) {
|
|
1107
|
+
chunks.push(ts_poet_1.code `
|
|
1108
|
+
fromPartial<I extends ${utils.Exact}<${utils.DeepPartial}<${fullName}>, I>>(${paramName}: I): ${fullName} {
|
|
1109
|
+
`);
|
|
1110
|
+
}
|
|
1111
|
+
else {
|
|
1112
|
+
chunks.push(ts_poet_1.code `
|
|
1113
|
+
fromPartial(${paramName}: ${utils.DeepPartial}<${fullName}>): ${fullName} {
|
|
1114
|
+
`);
|
|
1115
|
+
}
|
|
1116
|
+
chunks.push(ts_poet_1.code `const message = createBase${fullName}();`);
|
|
1111
1117
|
// add a check for each incoming field
|
|
1112
1118
|
messageDesc.field.forEach((field) => {
|
|
1113
1119
|
const fieldName = case_1.maybeSnakeToCamel(field.name, options);
|
package/build/options.js
CHANGED