From a7e60112649e6e7e4cbbbb819bd7b94a0e33e11d Mon Sep 17 00:00:00 2001 From: Jonathan Haines Date: Fri, 31 Jul 2020 11:20:02 +1000 Subject: [PATCH] refactor: CSS Style Declaration types to support latest TypeScript --- lib/assertions.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/assertions.ts b/lib/assertions.ts index 60f3ffa35..cd85da0c5 100644 --- a/lib/assertions.ts +++ b/lib/assertions.ts @@ -24,9 +24,9 @@ export interface ExistsOptions { count: number; } -export interface Dictionary { - [key: string]: T; -} +type CSSStyleDeclarationProperty = keyof CSSStyleDeclaration; + +type ActualCSSStyleDeclaration = Partial>; export default class DOMAssertions { constructor( @@ -730,14 +730,14 @@ export default class DOMAssertions { */ hasPseudoElementStyle( selector: string | null, - expected: Dictionary, + expected: Record, message?: string ): DOMAssertions { let element = this.findTargetElement(); if (!element) return this; let computedStyle = window.getComputedStyle(element, selector); - let expectedProperties = Object.keys(expected) as [keyof CSSStyleDeclaration]; + let expectedProperties = Object.keys(expected) as CSSStyleDeclarationProperty[]; if (expectedProperties.length <= 0) { throw new TypeError( `Missing style expectations. There must be at least one style property in the passed in expectation object.` @@ -747,7 +747,7 @@ export default class DOMAssertions { let result = expectedProperties.every( property => computedStyle[property] === expected[property] ); - let actual: Dictionary = {}; + let actual: ActualCSSStyleDeclaration = {}; expectedProperties.forEach(property => (actual[property] = computedStyle[property])); @@ -800,7 +800,7 @@ export default class DOMAssertions { */ doesNotHavePseudoElementStyle( selector: string | null, - expected: Dictionary, + expected: Record, message: string ): DOMAssertions { let element = this.findTargetElement(); @@ -808,7 +808,7 @@ export default class DOMAssertions { let computedStyle = window.getComputedStyle(element, selector); - let expectedProperties = Object.keys(expected) as [keyof CSSStyleDeclaration]; + let expectedProperties = Object.keys(expected) as CSSStyleDeclarationProperty[]; if (expectedProperties.length <= 0) { throw new TypeError( `Missing style expectations. There must be at least one style property in the passed in expectation object.` @@ -818,7 +818,7 @@ export default class DOMAssertions { let result = expectedProperties.some( property => computedStyle[property] !== expected[property] ); - let actual: Dictionary = {}; + let actual: ActualCSSStyleDeclaration = {}; expectedProperties.forEach(property => (actual[property] = computedStyle[property]));