Skip to content

Commit

Permalink
refactor: make WithEscapeHatch<T> much more performant (#2816)
Browse files Browse the repository at this point in the history
  • Loading branch information
devunt authored Aug 25, 2024
1 parent bf488fe commit 8c276ff
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .changeset/fresh-dodos-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@pandacss/generator': patch
'@pandacss/studio': patch
---

make `WithEscapeHatch<T>` much more performant

This pull request is a follow-up pull request to #2466.

Make `WithEscapeHatch<T>` much more performant and typescript happy by updating the type signature of `WithImportant<T>`
and `WithColorOpacityModifier<T>` to use _branded type_ and _non-distributive conditional types_, while keeping such
tokens valid and also not appearing in autocompletions to prevent them from polluting autocompletion result (which is
the current behavior).
8 changes: 4 additions & 4 deletions packages/generator/__tests__/generate-prop-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ describe('generate property types', () => {
type WithColorOpacityModifier<T> = T extends string ? \`\${T}/\${string}\` : T
type WithColorOpacityModifier<T> = [T] extends [string] ? \`\${T}/\${string}\` & { __colorOpacityModifier?: true } : never
type ImportantMark = "!" | "!important"
type WhitespaceImportant = \` \${ImportantMark}\`
type Important = ImportantMark | WhitespaceImportant
type WithImportant<T> = T extends string ? \`\${T}\${Important}\` & { __important?: true } : T;
type WithImportant<T> = [T] extends [string] ? \`\${T}\${Important}\` & { __important?: true } : never
/**
* Only relevant when using \`strictTokens\` or \`strictPropertyValues\` in your config.
Expand Down Expand Up @@ -283,12 +283,12 @@ describe('generate property types', () => {
type WithColorOpacityModifier<T> = T extends string ? \`\${T}/\${string}\` : T
type WithColorOpacityModifier<T> = [T] extends [string] ? \`\${T}/\${string}\` & { __colorOpacityModifier?: true } : never
type ImportantMark = "!" | "!important"
type WhitespaceImportant = \` \${ImportantMark}\`
type Important = ImportantMark | WhitespaceImportant
type WithImportant<T> = T extends string ? \`\${T}\${Important}\` & { __important?: true } : T;
type WithImportant<T> = [T] extends [string] ? \`\${T}\${Important}\` & { __important?: true } : never
/**
* Only relevant when using \`strictTokens\` or \`strictPropertyValues\` in your config.
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/src/artifacts/types/prop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export function generatePropTypes(ctx: Context) {
return outdent`
${result.join('\n')}
type WithColorOpacityModifier<T> = T extends string ? \`$\{T}/\${string}\` : T
type WithColorOpacityModifier<T> = [T] extends [string] ? \`$\{T}/\${string}\` & { __colorOpacityModifier?: true } : never
type ImportantMark = "!" | "!important"
type WhitespaceImportant = \` \${ImportantMark}\`
type Important = ImportantMark | WhitespaceImportant
type WithImportant<T> = T extends string ? \`\${T}\${Important}\` & { __important?: true } : T;
type WithImportant<T> = [T] extends [string] ? \`\${T}\${Important}\` & { __important?: true } : never
/**
* Only relevant when using \`strictTokens\` or \`strictPropertyValues\` in your config.
Expand Down
4 changes: 2 additions & 2 deletions packages/studio/styled-system/types/prop-type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ export interface UtilityValues {



type WithColorOpacityModifier<T> = T extends string ? `${T}/${string}` : T
type WithColorOpacityModifier<T> = [T] extends [string] ? `${T}/${string}` & { __colorOpacityModifier?: true } : never

type ImportantMark = "!" | "!important"
type WhitespaceImportant = ` ${ImportantMark}`
type Important = ImportantMark | WhitespaceImportant
type WithImportant<T> = T extends string ? `${T}${Important}` & { __important?: true } : T;
type WithImportant<T> = [T] extends [string] ? `${T}${Important}` & { __important?: true } : never

/**
* Only relevant when using `strictTokens` or `strictPropertyValues` in your config.
Expand Down

0 comments on commit 8c276ff

Please sign in to comment.