diff --git a/docs/modules/Json.ts.md b/docs/modules/Json.ts.md index 2ecbffff8..cad3fc971 100644 --- a/docs/modules/Json.ts.md +++ b/docs/modules/Json.ts.md @@ -49,7 +49,7 @@ Added in v2.10.0 ```ts export interface JsonRecord { - readonly [key: string]: Json + readonly [key: string]: Json | undefined } ``` diff --git a/dtslint/ts3.5/Json.ts b/dtslint/ts3.5/Json.ts index 8e568d1c8..eb9056b50 100644 --- a/dtslint/ts3.5/Json.ts +++ b/dtslint/ts3.5/Json.ts @@ -2,6 +2,16 @@ import * as E from '../../src/Either' import { pipe } from '../../src/function' import * as _ from '../../src/Json' +declare const jr: _.JsonRecord + +// +// JsonRecord +// + +// $ExpectError +const foo1: _.Json = jr.foo +const foo2: _.Json | undefined = jr.foo + // // stringify // @@ -12,10 +22,6 @@ _.stringify<_.Json>(undefined) _.stringify<_.Json>(() => {}) // $ExpectError _.stringify<_.Json>(Symbol()) -// $ExpectError -_.stringify<_.Json>({ a: undefined }) -// $ExpectError -_.stringify<_.Json>({ ...{ a: undefined } }) // tslint:disable-next-line: interface-over-type-literal interface AB { diff --git a/package-lock.json b/package-lock.json index 9cf6fb658..487afcf03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2350,7 +2350,7 @@ } }, "dtslint": { - "version": "github:gcanti/dtslint#2c3c3487e7650d6ca90c2877dbbd7c4c08360d0d", + "version": "github:gcanti/dtslint#ef28f0ad1d3bd64b8367f6f543cf6fd3b9b09c1b", "from": "github:gcanti/dtslint", "dev": true, "requires": { diff --git a/src/Json.ts b/src/Json.ts index 4a188af53..67b7a8632 100644 --- a/src/Json.ts +++ b/src/Json.ts @@ -13,7 +13,7 @@ export type Json = boolean | number | string | null | JsonArray | JsonRecord * @since 2.10.0 */ export interface JsonRecord { - readonly [key: string]: Json + readonly [key: string]: Json | undefined } /** diff --git a/test/Json.ts b/test/Json.ts index 060baf731..efcd243d7 100644 --- a/test/Json.ts +++ b/test/Json.ts @@ -11,6 +11,7 @@ describe('Json', () => { it('stringify', () => { U.deepStrictEqual(pipe({ a: 1 }, _.stringify), E.right('{"a":1}')) + U.deepStrictEqual(pipe({ a: undefined }, _.stringify), E.right('{}')) const circular: any = { ref: null } circular.ref = circular U.deepStrictEqual(