Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): return type alias instead of string from css and cx #835

Merged
merged 1 commit into from Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';