Skip to content

Commit

Permalink
whitelist window in UnknownRecord, fix #413
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jan 22, 2020
1 parent 231b9f5 commit 9a4c6fa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
19 changes: 18 additions & 1 deletion dtslint/ts3.5/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Compact<A> = { [K in keyof A]: A[K] }
/**
* Returns the string literal 'T' if `A` and `B` are equal types, 'F' otherwise
*/
type Equals<A, B> = (<C>() => C extends Compact<A> ? 'T' : 'F') extends (<C>() => C extends Compact<B> ? 'T' : 'F')
type Equals<A, B> = (<C>() => C extends Compact<A> ? 'T' : 'F') extends <C>() => C extends Compact<B> ? 'T' : 'F'
? 'T'
: 'F'

Expand Down Expand Up @@ -582,3 +582,20 @@ const toNumber = (n: t.Int): number => n

// $ExpectError
const intToInt2 = (int: t.Int): Int2 => int

//
// UnknownRecord
//

// $ExpectError
const ur1: Record<string, unknown> = [1, 2, 3]
// $ExpectError
const ur2: Record<string, unknown> = new Date()
// tslint:disable: no-construct
// $ExpectError
const ur3: Record<string, unknown> = new Number()
// $ExpectError
const ur4: Record<string, unknown> = new String()
// $ExpectError
const ur5: Record<string, unknown> = new Boolean()
// tslint:enable: no-construct
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 9a4c6fa

Please sign in to comment.