frenic / csstype

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

Strict types #176

Open Farnsi opened 1 year ago

Farnsi commented 1 year ago

It would be great if this nice lib could export strict types, without(string & {}) everything.

Usage e.g. with import type * as CSS from 'csstype/strict';

If a non strict type is necessary, we could add it manually with a union or import the non-strict csstype.

heleg commented 11 months ago

Why did the author even add this (string & {}) ?

meyer commented 11 months ago

from the README:

  • TypeScript hack for autocompletion
    Uses (string & {}) for literal string unions and (number & {}) for literal number unions (related issue). Utilize PropertyValue<T> to unpack types from e.g. (string & {}) to string.
heleg commented 11 months ago

@meyer Thank you very much. Personally I was confused not by string | {} union but by string fallback in common. I had the very same question: https://github.com/frenic/csstype/issues/90#issuecomment-707851935 I found the answer because of your comment.

@Farnsi What the criteria of the "strict" in this case?

Farnsi commented 11 months ago

@heleg strict should be an export without string | {}, only defined properties

Example:

  export type Height<TLength = (string & {}) | 0> =
    | Globals
    | TLength
    | "-moz-max-content"
    | "-moz-min-content"
    | "-webkit-fit-content"
    | "auto"
    | "fit-content"
    | "max-content"
    | "min-content"
//    | (string & {});  // <--------- STRICT without that