Skip to content
Permalink
Browse files
fix(core): return type alias instead of string from css and cx (#835
)
  • Loading branch information
Anber committed Sep 12, 2021
1 parent ca5232a commit 7eb9d94dc2d9d79f7be0159c43fa5d71c96d7182
Showing with 17 additions and 5 deletions.
  1. +3 −1 packages/core/src/css.ts
  2. +13 −4 packages/core/src/cx.ts
  3. +1 −0 packages/core/src/index.ts
@@ -1,10 +1,12 @@
import type { CSSProperties } from './CSSProperties';
import type { StyledMeta } from './StyledMeta';

export type LinariaClassName = string & { __linariaClassName: true };

type CSS = (
strings: TemplateStringsArray,
...exprs: Array<string | number | CSSProperties | StyledMeta>
) => string;
) => LinariaClassName;

const css: CSS = () => {
throw new Error(
@@ -1,9 +1,18 @@
export type ClassName = string | false | void | null | 0;
import { LinariaClassName } from './css';

type CX = (...classNames: ClassName[]) => string;
export type ClassName<T = string> = T | false | void | null | 0 | '';

const cx: CX = function cx() {
return Array.prototype.slice.call(arguments).filter(Boolean).join(' ');
interface ICX {
(...classNames: ClassName<LinariaClassName>[]): LinariaClassName;
(...classNames: ClassName[]): string;
}

const cx: ICX = function cx() {
const result = Array.prototype.slice
.call(arguments)
.filter(Boolean)
.join(' ');
return result as LinariaClassName;
};

export default cx;
@@ -2,3 +2,4 @@ export { default as css } from './css';
export { default as cx } from './cx';
export type { CSSProperties } from './CSSProperties';
export type { StyledMeta } from './StyledMeta';
export type { LinariaClassName } from './css';

0 comments on commit 7eb9d94

Please sign in to comment.