frenic / csstype

Strict TypeScript and Flow types for style based on MDN data
MIT License
1.73k stars 72 forks source link

Mark fallback arrays as immutable #110

Closed kripod closed 1 year ago

kripod commented 4 years ago

Fallback values should be readonly to support assigning ["fallback", "values"] as const, e.g.:

import type { PropertiesFallback as CSSProperties } from "csstype";

export function placeContent<
  Align extends CSSProperties["alignContent"],
  Justify extends CSSProperties["justifyContent"] = Align
>(
  align: Align,
  justify: Justify = (align as unknown) as Justify,
): {
  alignContent: Align;
  justifyContent: Justify;
} {
  return {
    alignContent: align,
    justifyContent: justify,
  };
}

const longhands = placeContent(["space-around", "space-evenly"] as const);

// Type should be inferred as:
// {
//   alignContent: readonly ["space-around", "space-evenly"];
//   justifyContent: readonly ["space-around", "space-evenly"];
// }