Skip to content

Commit

Permalink
fix: issue with type checker false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Apr 11, 2023
1 parent 9910449 commit c7de5e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-planets-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@svbstrate/core": patch
---

Fix issue where merging presets would fool the checker into thinking all theme values were defined
3 changes: 2 additions & 1 deletion packages/core/lib/__tests__/test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare module "../" {
}

interface Shorthands extends s.PresetShorthands {
pl: s.MapShorthandToToken<"paddingLeft", "space">;
foo: s.MapShorthandToToken<'color', 'color'>;
}

interface Macros extends s.PresetMacros {
Expand Down Expand Up @@ -40,6 +40,7 @@ const theme = s.createTheme({
},
shorthands: {
...presets.shorthands,
foo: ["color"],
},
macros: {
...presets.macros,
Expand Down
16 changes: 11 additions & 5 deletions packages/core/lib/presets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ThemeConfig } from "./types";
import * as types from "./types";

export const breakpoints: ThemeConfig["breakpoints"] = [
export const breakpoints: types.ThemeConfig["breakpoints"] = [
"400px",
"800px",
"1200px",
];

export const tokens: ThemeConfig["tokens"] = {
export const tokens: {
[Token in keyof types.PresetTokens]: types.PresetTokens[Token];
} = {
space: [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64],
fontSize: ["3rem", "3rem", "2.2rem", "1.8rem", "1.4rem", "1rem", "0.875rem"],
fontWeight: [
Expand All @@ -25,7 +27,9 @@ export const tokens: ThemeConfig["tokens"] = {
lineHeight: [1.1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6],
};

export const shorthands: ThemeConfig["shorthands"] = {
export const shorthands: {
[Shorthand in keyof types.PresetShorthands]: (keyof types.CSSProperties)[];
} = {
d: ["display"],
w: ["width"],
h: ["height"],
Expand Down Expand Up @@ -53,7 +57,9 @@ export const shorthands: ThemeConfig["shorthands"] = {
ta: ["textAlign"],
};

export const macros: ThemeConfig["macros"] = {
export const macros: {
[Macro in keyof types.PresetMacros]: types.SvbstrateCSSStyleObject;
} = {
db: { display: "block" },
dib: { display: "inline-block" },
di: { display: "inline" },
Expand Down

0 comments on commit c7de5e7

Please sign in to comment.