Skip to content

Commit

Permalink
feat: improve typing (#34)
Browse files Browse the repository at this point in the history
* fix: update so original clss name comes through from css

* fix: tests now pass

* fix: add better typing for JSX and ReactNode

---------

Co-authored-by: Andy Wilson <andy@builtbypixel.com>
  • Loading branch information
The-Code-Monkey and Andy Wilson committed Mar 26, 2024
1 parent c6eb795 commit e3b174a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

npm run build
npm test
8 changes: 5 additions & 3 deletions fixtures/Foo.mist.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Generated by MistCSS, do not modify
import './Foo.mist.css'

import type { JSX, ReactNode } from 'react';

type FooProps = {
children?: React.ReactNode
children?: ReactNode
fooSize?: 'lg' | 'sm'
x?: boolean
} & JSX.IntrinsicElements['div']
Expand All @@ -16,7 +18,7 @@ export function Foo({ children, fooSize, x, ...props }: FooProps) {
}

type BarProps = {
children?: React.ReactNode
children?: ReactNode
barSize?: 'lg'
x?: boolean
} & JSX.IntrinsicElements['span']
Expand All @@ -30,7 +32,7 @@ export function Bar({ children, barSize, x, ...props }: BarProps) {
}

type BazProps = {
children?: React.ReactNode
children?: ReactNode
} & JSX.IntrinsicElements['p']

export function Baz({ children, ...props }: BazProps) {
Expand Down
4 changes: 3 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Components } from './parser.js'

function renderProps(component: Component): string {
return Object.entries({
children: 'React.ReactNode',
children: 'ReactNode',
...component.data,
})
.map(([key, value]) => {
Expand Down Expand Up @@ -52,6 +52,8 @@ export function render(name: string, components: Components): string {
return `// Generated by MistCSS, do not modify
import './${name}.mist.css'
import type { JSX, ReactNode } from 'react';
${Object.keys(components)
.map((key) => renderComponent(components, key))
.join('\n')
Expand Down

0 comments on commit e3b174a

Please sign in to comment.