csstype icon indicating copy to clipboard operation
csstype copied to clipboard

Strict types

Open Farnsi opened this issue 2 years ago • 4 comments

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.

Farnsi avatar Mar 16 '23 10:03 Farnsi

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

heleg avatar Jul 30 '23 18:07 heleg

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.

meyer avatar Jul 30 '23 18:07 meyer

@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?

heleg avatar Jul 30 '23 20:07 heleg

@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

Farnsi avatar Jul 31 '23 08:07 Farnsi