diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d5ecb252..a1523f422 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ **Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice. +# 2.0.6 + +- **Bug Fix** + - whitelist `window` in `UnknownRecord`, fix #413 (@gcanti) + # 2.0.5 - **Bug Fix** diff --git a/dtslint/ts3.5/index.ts b/dtslint/ts3.5/index.ts index 549404c29..69c1cbc19 100644 --- a/dtslint/ts3.5/index.ts +++ b/dtslint/ts3.5/index.ts @@ -10,7 +10,7 @@ type Compact = { [K in keyof A]: A[K] } /** * Returns the string literal 'T' if `A` and `B` are equal types, 'F' otherwise */ -type Equals = (() => C extends Compact ? 'T' : 'F') extends (() => C extends Compact ? 'T' : 'F') +type Equals = (() => C extends Compact ? 'T' : 'F') extends () => C extends Compact ? 'T' : 'F' ? 'T' : 'F' @@ -582,3 +582,20 @@ const toNumber = (n: t.Int): number => n // $ExpectError const intToInt2 = (int: t.Int): Int2 => int + +// +// UnknownRecord +// + +// $ExpectError +const ur1: Record = [1, 2, 3] +// $ExpectError +const ur2: Record = new Date() +// tslint:disable: no-construct +// $ExpectError +const ur3: Record = new Number() +// $ExpectError +const ur4: Record = new String() +// $ExpectError +const ur5: Record = new Boolean() +// tslint:enable: no-construct diff --git a/package.json b/package.json index 33e62ee19..97766aac8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "io-ts", - "version": "2.0.5", + "version": "2.0.6", "description": "TypeScript compatible runtime type system for IO validation", "files": [ "lib", diff --git a/src/index.ts b/src/index.ts index 518882320..d1e527479 100644 --- a/src/index.ts +++ b/src/index.ts @@ -416,7 +416,10 @@ export class AnyDictionaryType extends Type<{ [key: string]: unknown }> { constructor() { super( 'UnknownRecord', - (u): u is { [key: string]: unknown } => Object.prototype.toString.call(u) === '[object Object]', + (u): u is { [key: string]: unknown } => { + const s = Object.prototype.toString.call(u) + return s === '[object Object]' || s === '[object Window]' + }, (u, c) => (this.is(u) ? success(u) : failure(u, c)), identity )