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

error TS2345: Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'CreateCSSProperties #40535

Open
cmoulliard opened this issue Jan 11, 2024 · 3 comments
Assignees
Labels
customization: css Design CSS customizability v4.x

Comments

@cmoulliard
Copy link

cmoulliard commented Jan 11, 2024

Steps to reproduce

Steps:

  1. Git clone this project and PR: Image build using backstage dockerfile dont run on ocp q-shift/backstage-playground#2
  2. cd plugins/quarkus
  3. yarn install; yarn tsc

Current behavior

The following code (see here)

onst Tag: ComponentClass = styled(({ label, onDelete, ...props }) => (
    <div {...props}>
        <span>{label}</span>
        <CloseIcon onClick={onDelete} />
    </div>
))`
  display: flex;
  align-items: center;
  height: 24px;
  margin: 2px;
  line-height: 22px;
  background-color: #fafafa;
  border: 1px solid #e8e8e8;
  border-radius: 2px;
  box-sizing: content-box;
  padding: 0 4px 0 10px;
  outline: 0;
  overflow: hidden;

  &:focus {
    border-color: #40a9ff;
    background-color: #e6f7ff;
  }

  & span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  & svg {
    font-size: 12px;
    cursor: pointer;
    padding: 4px;
  }
`;

generates this error when we execute yarn tsc

src/scaffolder/QuarkusExtensionList.tsx:57:3 - 
error TS2345: Argument of type 'TemplateStringsArray' is not assignable to parameter of type
'CreateCSSProperties<(value: string, index: number, array: readonly string[]) => unknown> | ((props: { theme: Theme; } & ((value: string, index: number, array: readonly string[]) => unknown)) => CreateCSSProperties<...>)'.

 57 ))`
      ~
 58   display: flex;
    ~~~~~~~~~~~~~~~~
... 
 86   }
    ~~~
 87 `;
    ~

using such versions of material-ui:

  • "@material-ui/core": "^4.12.4",
  • "@material-ui/lab": "^4.0.0-alpha.61"

Expected behavior

No error should be reported

Context

I try to publish my project as npmjs.org module and it is needed to run "yarn tsc" in that case. This is how I got this error that we don't have when the plugin is used directly locally in backstage.

Your environment

  System:
    OS: macOS 13.6.3
  Binaries:
    Node: 19.9.0 - ~/.nvm/versions/node/v19.9.0/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v19.9.0/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 120.0.6099.199
    Edge: Not Found
    Safari: 17.2
  npmPackages:
    @emotion/react:  11.11.3 
    @emotion/styled:  11.11.0 
    @mui/base:  5.0.0-beta.31 
    @mui/core-downloads-tracker:  5.15.4 
    @mui/material:  5.15.4 
    @mui/private-theming:  5.15.4 
    @mui/styled-engine:  5.15.4 
    @mui/system:  5.15.4 
    @mui/types:  7.2.13 
    @mui/utils:  5.15.4 
    @types/react:  17.0.74 
    styled-components: ^6.1.8 => 6.1.8 
    typescript:  5.1.6 

and typeconfig.json

{
  "extends": "@backstage/cli/config/tsconfig.json",
  "include": [
    "src",
  ],
  "exclude": ["node_modules"],
  "compilerOptions": {
    "noImplicitAny": false,
    "outDir": "dist-types",
    "rootDir": "."
  }
}

Search keywords: TS2345, typescript, not assignable to parameter of type

@cmoulliard cmoulliard added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 11, 2024
@zannager zannager added the customization: css Design CSS customizability label Jan 11, 2024
@mnajdova mnajdova added the v4.x label Jan 11, 2024
@siriwatknp
Copy link
Member

Can you try converting the template string to CSS object?

@siriwatknp siriwatknp added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 21, 2024
@cmoulliard
Copy link
Author

converting the template string

Which template string ?

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Feb 21, 2024
@siriwatknp
Copy link
Member

onst Tag: ComponentClass = styled(({ label, onDelete, ...props }) => (
    <div {...props}>
        <span>{label}</span>
        <CloseIcon onClick={onDelete} />
    </div>
))`...` << template string

try this:

onst Tag: ComponentClass = styled(({ label, onDelete, ...props }) => (
    <div {...props}>
        <span>{label}</span>
        <CloseIcon onClick={onDelete} />
    </div>
))({
  display: "flex",
  alignItems: "center",
  height: "24px",
  margin: "2px",
  lineHeight: "22px",
  backgroundColor: "#fafafa",
  border: "1px solid #e8e8e8",
  borderRadius: "2px",
  boxSizing: "content-box",
  padding: "0 4px 0 10px",
  outline: "0",
  overflow: "hidden",
  "&:focus": { borderColor: "#40a9ff", backgroundColor: "#e6f7ff" },
  "& span": {
    overflow: "hidden",
    whiteSpace: "nowrap",
    textOverflow: "ellipsis"
  },
  "& svg": { fontSize: "12px", cursor: "pointer", padding: "4px" }
})

@samuelsycamore samuelsycamore removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: css Design CSS customizability v4.x
Projects
None yet
Development

No branches or pull requests

5 participants