Skip to content

fix: generated CssVarKeys type cannot provide autocomplete correctly #3177

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-plums-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pandacss/generator': patch
---

Fix issue where generated `CssVarKeys` type cannot provide autocomplete correctly
12 changes: 6 additions & 6 deletions packages/generator/__tests__/generate-style-props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ describe('generate property types', () => {
type CssVars = \`var(--\${string})\`
type CssVarValue = ConditionalValue<Token | AnyString | (number & {})>

type CssVarName = | AnyString
type CssVarKeys = \`--\${CssVarName}\`
type CssVarName = AnyString
type CssVarKeys = \`--\${CssVarName}\` | \`--\${string}\` & {}

export type CssVarProperties = {
[key in CssVarKeys]?: CssVarValue
Expand Down Expand Up @@ -7510,8 +7510,8 @@ describe('generate property types', () => {
type CssVars = \`var(--\${string})\`
type CssVarValue = ConditionalValue<Token | AnyString | (number & {})>

type CssVarName = | AnyString
type CssVarKeys = \`--\${CssVarName}\`
type CssVarName = AnyString
type CssVarKeys = \`--\${CssVarName}\` | \`--\${string}\` & {}

export type CssVarProperties = {
[key in CssVarKeys]?: CssVarValue
Expand Down Expand Up @@ -15024,8 +15024,8 @@ describe('generate property types', () => {
type CssVars = "var(--random-color)" | "var(--button-color)"
type CssVarValue = ConditionalValue<Token | CssVars | AnyString | (number & {})>

type CssVarName = "random-color" | "button-color" | AnyString
type CssVarKeys = \`--\${CssVarName}\`
type CssVarName = "random-color" | "button-color"
type CssVarKeys = \`--\${CssVarName}\` | \`--\${string}\` & {}

export type CssVarProperties = {
[key in CssVarKeys]?: CssVarValue
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/src/artifacts/types/style-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function generateStyleProps(ctx: Context) {
type CssVars = ${[cssVars || '`var(--${string})`'].filter(Boolean).join(' | ')}
type CssVarValue = ConditionalValue<Token${ctx.globalVars.isEmpty() ? '' : ' | CssVars'} | AnyString | (number & {})>

type CssVarName = ${unionType(ctx.globalVars.names)} | AnyString
type CssVarKeys = \`--\${CssVarName}\`
type CssVarName = ${unionType(ctx.globalVars.names) || 'AnyString'}
type CssVarKeys = \`--\${CssVarName}\` | \`--\${string}\` & {}

export type CssVarProperties = {
[key in CssVarKeys]?: CssVarValue
Expand Down
2 changes: 1 addition & 1 deletion packages/studio/styled-system/types/conditions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export interface Conditions {
"_open": string
/** `&:is([closed], [data-closed], [data-state="closed"])` */
"_closed": string
/** `&is(:fullscreen, [data-fullscreen])` */
/** `&:is(:fullscreen, [data-fullscreen])` */
"_fullscreen": string
/** `&:is([data-loading], [aria-busy=true])` */
"_loading": string
Expand Down
4 changes: 2 additions & 2 deletions packages/studio/styled-system/types/style-props.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type AnyString = (string & {})
type CssVars = `var(--${string})`
type CssVarValue = ConditionalValue<Token | AnyString | (number & {})>

type CssVarName = | AnyString
type CssVarKeys = `--${CssVarName}`
type CssVarName =
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I prevent this empty type? I tried to fix this by editting style-props.ts, but it didn't work.

type CssVarKeys = `--${CssVarName}` | `--${string}` & {}

export type CssVarProperties = {
[key in CssVarKeys]?: CssVarValue
Expand Down