cssinjs / jss

JSS is an authoring tool for CSS which uses JavaScript as a host language.
https://cssinjs.org
MIT License
7.08k stars 399 forks source link

TypeScript compilation error when using array for @font-face #1422

Closed patrickjtoy closed 3 years ago

patrickjtoy commented 4 years ago

Expected behavior: According to the documentation the following should work:

// Multiple font faces.
const styles = {
  '@font-face': [
    {
      fontFamily: 'MyWebFont',
      src: 'url(webfont.eot)'
    },
    {
      fontFamily: 'MySecondFont',
      src: 'url(webfont2.eot)'
    }
  ]
}

From that, I expect that the following should also work:

const useStyles = createUseStyles({
  "@font-face": [
    {
      fontFamily: "MyWebFont",
      src: "url(webfont.eot)"
    },
    {
      fontFamily: "MySecondFont",
      src: "url(webfont2.eot)"
    }
  ]
});

Describe the bug:

(property) "@font-face": string | JssStyle | Func<string | JssStyle | null | undefined>
Type '{ fontFamily: string; src: string; }[]' is not assignable to type 'string | JssStyle | Func<string | JssStyle | null | undefined>'.
  Type '{ fontFamily: string; src: string; }[]' is not assignable to type 'JssStyle'.
    Index signature is missing in type '{ fontFamily: string; src: string; }[]'.ts(2322)

Codesandbox link: https://codesandbox.io/s/stupefied-chandrasekhar-quii5?file=/src/App.tsx

Versions (please complete the following information):

kof commented 3 years ago

Feel free to send a PR for the type fix

PetrBorisov commented 3 years ago

looks like it might be helpful https://github.com/cssinjs/jss/pull/1521

kof commented 3 years ago

released in https://github.com/cssinjs/jss/releases/tag/v10.7.0