Skip to content

Commit 183e4e6

Browse files
authored
refactor(types): use template literal types insteads of any (#4166)
1 parent e816812 commit 183e4e6

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

packages/runtime-dom/src/components/Transition.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import { isObject, toNumber, extend, isArray } from '@vue/shared'
1212
const TRANSITION = 'transition'
1313
const ANIMATION = 'animation'
1414

15+
type AnimationTypes = typeof TRANSITION | typeof ANIMATION
16+
1517
export interface TransitionProps extends BaseTransitionProps<Element> {
1618
name?: string
17-
type?: typeof TRANSITION | typeof ANIMATION
19+
type?: AnimationTypes
1820
css?: boolean
1921
duration?: number | { enter: number; leave: number }
2022
// custom transition classes
@@ -368,24 +370,33 @@ function whenTransitionEnds(
368370
}
369371

370372
interface CSSTransitionInfo {
371-
type: typeof TRANSITION | typeof ANIMATION | null
373+
type: AnimationTypes | null
372374
propCount: number
373375
timeout: number
374376
hasTransform: boolean
375377
}
376378

379+
type AnimationProperties = 'Delay' | 'Duration'
380+
type StylePropertiesKey =
381+
| `${AnimationTypes}${AnimationProperties}`
382+
| `${typeof TRANSITION}Property`
383+
377384
export function getTransitionInfo(
378385
el: Element,
379386
expectedType?: TransitionProps['type']
380387
): CSSTransitionInfo {
381-
const styles: any = window.getComputedStyle(el)
388+
const styles = window.getComputedStyle(el) as Pick<
389+
CSSStyleDeclaration,
390+
StylePropertiesKey
391+
>
382392
// JSDOM may return undefined for transition properties
383-
const getStyleProperties = (key: string) => (styles[key] || '').split(', ')
384-
const transitionDelays = getStyleProperties(TRANSITION + 'Delay')
385-
const transitionDurations = getStyleProperties(TRANSITION + 'Duration')
393+
const getStyleProperties = (key: StylePropertiesKey) =>
394+
(styles[key] || '').split(', ')
395+
const transitionDelays = getStyleProperties(`${TRANSITION}Delay`)
396+
const transitionDurations = getStyleProperties(`${TRANSITION}Duration`)
386397
const transitionTimeout = getTimeout(transitionDelays, transitionDurations)
387-
const animationDelays = getStyleProperties(ANIMATION + 'Delay')
388-
const animationDurations = getStyleProperties(ANIMATION + 'Duration')
398+
const animationDelays = getStyleProperties(`${ANIMATION}Delay`)
399+
const animationDurations = getStyleProperties(`${ANIMATION}Duration`)
389400
const animationTimeout = getTimeout(animationDelays, animationDurations)
390401

391402
let type: CSSTransitionInfo['type'] = null
@@ -420,7 +431,9 @@ export function getTransitionInfo(
420431
}
421432
const hasTransform =
422433
type === TRANSITION &&
423-
/\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property'])
434+
/\b(transform|all)(,|$)/.test(
435+
getStyleProperties(`${TRANSITION}Property`).toString()
436+
)
424437
return {
425438
type,
426439
timeout,

0 commit comments

Comments
 (0)