Skip to content

Commit 822731e

Browse files
authored
Merge pull request #6 from mojotech/em/fixes
Pin typescript version to avoid prematurely upgrading to 2.7 Disable tslint warning due to bad type inference
2 parents 4404561 + 590497a commit 822731e

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"tslint-config-standard": "^7.0.0",
8686
"typedoc": "^0.9.0",
8787
"typedoc-plugin-markdown": "^1.0.12",
88-
"typescript": "^2.6.2",
88+
"typescript": "~2.6.2",
8989
"validate-commit-msg": "^2.12.2"
9090
}
9191
}

src/decoder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export class Decoder<A> {
241241
if (decoders.hasOwnProperty(key)) {
242242
const r = decoders[key].decode(json[key]);
243243
if (r.ok === true) {
244+
// tslint:disable-next-line:strict-type-predicates
244245
if (r.result !== undefined) {
245246
obj[key] = r.result;
246247
}

test/json-decode.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ describe('object', () => {
251251
result: {a: true, b: 'hats'}
252252
});
253253
});
254+
255+
it('ignores optional fields that decode to undefined', () => {
256+
const decoder = object({
257+
a: number(),
258+
b: optional(string())
259+
});
260+
261+
expect(decoder.run({a: 12, b: 'hats'})).toEqual({ok: true, result: {a: 12, b: 'hats'}});
262+
expect(decoder.run({a: 12})).toEqual({ok: true, result: {a: 12}});
263+
});
254264
});
255265

256266
describe('array', () => {

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,9 +3472,9 @@ typescript@2.4.1:
34723472
version "2.4.1"
34733473
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.1.tgz#c3ccb16ddaa0b2314de031e7e6fee89e5ba346bc"
34743474

3475-
typescript@^2.6.2:
3476-
version "2.7.1"
3477-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359"
3475+
typescript@~2.6.2:
3476+
version "2.6.2"
3477+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
34783478

34793479
uglify-js@^2.6:
34803480
version "2.8.29"

0 commit comments

Comments
 (0)