Skip to content

Commit

Permalink
Fix css helper function types
Browse files Browse the repository at this point in the history
  • Loading branch information
drozdzynski committed Oct 29, 2024
1 parent 74a5c03 commit 7e1b1e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-timers-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@teiler/core": patch
---

Fix `css` helper function types
5 changes: 3 additions & 2 deletions packages/core/src/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ function keyframes(strings: ReadonlyArray<string>, ...properties: Raw[]): StyleD
}
}

function css<Props>(strings: ReadonlyArray<string>, ...properties: Exclude<Properties<Props>, Expression<Props>>[]): CSS<Props> {
const style: Style<Props> = [Array.from(strings), properties]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function css(strings: ReadonlyArray<string>, ...properties: Exclude<Properties<any>, Expression<unknown>>[]): CSS<unknown> {
const style: Style<unknown> = [Array.from(strings), properties]
const styles = [style]
const id = styles.reduce((acc, [strings]) => acc + strings.join(''), '')
return { styles: styles, id: 't' + hash(id), __css__: true }
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import type { HTMLElements } from './tags'
import tags from './tags'
import hash from './hash'

type PropertiesWithPattern<Props> = Properties<Props> | Pattern<HTMLElements, Props>

type Pattern<Target extends HTMLElements, Props = {}> = {
styles: Style<Props>[]
type Pattern<Target extends HTMLElements, Props> = {
styles: Array<Style<Props>>,
tag: Target
id: string
__pattern__: true
Expand All @@ -17,14 +15,14 @@ type ExtendCallback<Target extends HTMLElements, Props> = <Component>(string: Re

type Constructor<Target extends HTMLElements> = {
<Props = {}>(pattern: Pattern<Target, Props>): ExtendCallback<Target, Props>
<Props = {}>(string: ReadonlyArray<string>, ...properties: PropertiesWithPattern<Props>[]): Pattern<Target, Props>
<Props = {}>(string: ReadonlyArray<string>, ...properties: Properties<Props>[]): Pattern<Target, Props>
}

type Infer<Component, Props> = Component extends Pattern<HTMLElements, infer P> ? P & Props : Props

const construct = <Target extends HTMLElements>(tag: Target) => {
function create<Props = {}>(stringOrPattern: Pattern<Target, Props>): ExtendCallback<Target, Props>
function create<Props = {}>(stringOrPattern: ReadonlyArray<string>, ...properties: PropertiesWithPattern<Props>[]): Pattern<Target, Props>
function create<Props = {}>(stringOrPattern: ReadonlyArray<string>, ...properties: Properties<Props>[]): Pattern<Target, Props>
function create<Props>(stringOrPattern: Pattern<Target, Props> | ReadonlyArray<string>, ...properties: Properties<Props>[]): Pattern<Target, Props> | ExtendCallback<Target, Props> {
if ('__pattern__' in stringOrPattern) {
return <Component>(strings: ReadonlyArray<string>, ...properties: Properties<Infer<Component, Props>>[]) => {
Expand Down

0 comments on commit 7e1b1e2

Please sign in to comment.