Repository: angular/angular
File: packages/core/src/animation/interfaces.ts (TypeScript)

Code before:
  {
    providedIn: 'root',
    factory: () => MAX_ANIMATION_TIMEOUT_DEFAULT,
  },
);
const MAX_ANIMATION_TIMEOUT_DEFAULT = 4000;

/**
 * The function type for `animate.enter` and `animate.leave` when they are used with
 * function callbacks.
 *
 * @publicApi 20.2
 */
export type AnimationFunction = (event: AnimationCallbackEvent) => void;

export type RunEnterAnimationFn = () => void;
export type RunLeaveAnimationFn = () => {promise: Promise<void>; resolve: VoidFunction};

export interface LongestAnimation {
  animationName: string | undefined;
  propertyName: string | undefined;
  duration: number;
}

export interface NodeAnimations<T> {
  animateFns: T[];
  resolvers?: VoidFunction[];
}

export interface AnimationLViewData {
  // Enter animations that apply to nodes in this view
  enter?: Map<number, NodeAnimations<RunEnterAnimationFn>>;

  // Leave animations that apply to nodes in this view
  leave?: Map<number, NodeAnimations<RunLeaveAnimationFn>>;

  // Leave animations that apply to nodes in this view
  // We chose to use unknown instead of PromiseSettledResult<void> to avoid requiring the type
  running?: Promise<unknown>;

  // Skip leave animations
  // This flag is solely used when move operations occur. DOM Node move
  // operations occur in lists, like `@for` loops, and use the same code
  // path during move that detaching or removing does. So to prevent
  // unexpected disappearing of moving nodes, we use this flag to skip
  // the animations in that case.
  skipLeaveAnimations?: boolean;
}


Review comment (suggestion):
I think given that this will only ever be 2 types, it would make more sense to just make this `RunEnterAnimationFn | RunLeaveAnimationFn`. It makes using the type less verbose.

Code after:
  {
    providedIn: 'root',
    factory: () => MAX_ANIMATION_TIMEOUT_DEFAULT,
  },
);
const MAX_ANIMATION_TIMEOUT_DEFAULT = 4000;

/**
 * The function type for `animate.enter` and `animate.leave` when they are used with
 * function callbacks.
 *
 * @publicApi 20.2
 */
export type AnimationFunction = (event: AnimationCallbackEvent) => void;

export type RunEnterAnimationFn = () => void;
export type RunLeaveAnimationFn = () => {promise: Promise<void>; resolve: VoidFunction};

export interface LongestAnimation {
  animationName: string | undefined;
  propertyName: string | undefined;
  duration: number;
}

export interface EnterNodeAnimations {
  animateFns: RunEnterAnimationFn[];
  resolvers?: VoidFunction[];
}
export interface LeaveNodeAnimations {
  animateFns: RunLeaveAnimationFn[];
  resolvers?: VoidFunction[];
}

export interface AnimationLViewData {
  // Enter animations that apply to nodes in this view
  enter?: Map<number, EnterNodeAnimations>;

  // Leave animations that apply to nodes in this view
  leave?: Map<number, LeaveNodeAnimations>;

  // Leave animations that apply to nodes in this view
  // We chose to use unknown instead of PromiseSettledResult<void> to avoid requiring the type
  running?: Promise<unknown>;

  // Skip leave animations
  // This flag is solely used when move operations occur. DOM Node move
  // operations occur in lists, like `@for` loops, and use the same code
  // path during move that detaching or removing does. So to prevent
  // unexpected disappearing of moving nodes, we use this flag to skip
  // the animations in that case.
  skipLeaveAnimations?: boolean;