Skip to content

Commit

Permalink
fix(core): return type alias instead of string from css and cx (#835
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Anber committed Sep 12, 2021
1 parent ca5232a commit 7eb9d94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/css.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(
Expand Down
17 changes: 13 additions & 4 deletions packages/core/src/cx.ts
@@ -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;
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Expand Up @@ -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.