diff --git a/.changeset/modern-months-attack.md b/.changeset/modern-months-attack.md new file mode 100644 index 0000000..c20faa6 --- /dev/null +++ b/.changeset/modern-months-attack.md @@ -0,0 +1,6 @@ +--- +"@teiler/svelte": patch +"@teiler/vue": patch +--- + +Change `strict` to `true` in `tsconfig.json` diff --git a/.changeset/slimy-taxis-rhyme.md b/.changeset/slimy-taxis-rhyme.md new file mode 100644 index 0000000..c08a15a --- /dev/null +++ b/.changeset/slimy-taxis-rhyme.md @@ -0,0 +1,5 @@ +--- +"@teiler/core": patch +--- + +Change `strict` to `true` in `tsconfig.json` diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 93f8ec7..3767c27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,7 +47,7 @@ jobs: - name: Install Dependencies run: | yarn install - yarn dlx playwright install --with-deps chromium + yarn playwright install --with-deps chromium - name: Build run: yarn build - name: Run tests diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index 81d6832..20afb88 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/package.json b/package.json index 5f13eb2..cdd89f7 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@typescript-eslint/eslint-plugin": "^8.1.0", "@typescript-eslint/parser": "^8.1.0", "eslint": "^9.9.0", + "playwright": "^1.48.0", "prettier": "^3.3.3", "prettier-plugin-svelte": "^3.2.6", "storybook": "^8.1.1", diff --git a/packages/core/src/constructor.test.ts b/packages/core/src/constructor.test.ts index 9ba9455..1007ed5 100644 --- a/packages/core/src/constructor.test.ts +++ b/packages/core/src/constructor.test.ts @@ -206,7 +206,7 @@ describe('insert', () => { hydrate: jest.fn<(ids: string[]) => void>(), } - const definition: StyleDefinition<'div', {}> = { + const definition: StyleDefinition = { id: 'teiler-1ep7axc', styles: [[['from { background-color: red; } to { background-color: green; }'], []]], tag: null, @@ -229,7 +229,7 @@ describe('insert', () => { hydrate: jest.fn<(ids: string[]) => void>(), } - const definition: StyleDefinition<'div', {}> = { + const definition: StyleDefinition = { id: 'tytz3vv', styles: [[['body { color: red; }'], []]], tag: null, diff --git a/packages/core/src/constructor.ts b/packages/core/src/constructor.ts index 98657a8..b0893af 100644 --- a/packages/core/src/constructor.ts +++ b/packages/core/src/constructor.ts @@ -5,23 +5,23 @@ import type { Pattern } from './pattern' import hash from './hash' import { compile, transpile } from './css' -type DefaultTheme = { [key: string]: string | boolean } +type DefaultTheme = {} type Arguments = { theme: DefaultTheme } & Props -type CSS = { styles: Style[]; id: string; __css__: true } -type Expression = (props: Arguments) => string | boolean | CSS +type CSS = { styles: Style[]; id: string; __css__: true } +type Expression = (props: Arguments) => string | boolean | CSS type Raw = string | number type Properties = Expression | StyleDefinition | Pattern | TeilerComponent | Raw type Style = [string[], Properties[]] -type StyleDefinition = { +type StyleDefinition = { type: 'component' | 'global' | 'keyframes' id: string styles: Array> - tag: Target | null + tag: Target } type TeilerComponent = { @@ -37,7 +37,7 @@ function styled>( createComponent: CreateCallback, stringOrBinded: TeilerComponent | ReadonlyArray, ...properties: Properties[] -): ExtendCallback | Type { +): Type | ExtendCallback { if (Array.isArray(stringOrBinded)) { const strings = stringOrBinded as ReadonlyArray const style: Style = [Array.from(strings), properties] @@ -45,7 +45,7 @@ function styled>( return createComponent(styleDefinition) } else { const binded = stringOrBinded as TeilerComponent - return (strings: ReadonlyArray, ...properties: Expression[]) => { + return (strings: ReadonlyArray, ...properties: Properties[]) => { const style: Style = [Array.from(strings), properties] const styleDefinition = compiler(binded.styleDefinition.tag, [...binded.styleDefinition.styles, style]) return createComponent(styleDefinition) @@ -53,7 +53,7 @@ function styled>( } } -type Compiler = (tag: Target, styles: Array>) => StyleDefinition +type Compiler = (tag: Target, styles: Array>) => StyleDefinition const component: Compiler = (tag: Target, styles: Array>): StyleDefinition => { const id = styles.reduce((acc, [strings]) => acc + strings.join(''), '') @@ -66,7 +66,7 @@ const component: Compiler = (tag: Target, st } } -const global: Compiler = (tag: null, styles: Array>): StyleDefinition => { +const global: Compiler = (tag: Target, styles: Array>): StyleDefinition => { const id = styles.reduce((acc, [strings]) => acc + strings.join(''), '') return { @@ -89,14 +89,14 @@ function keyframes(strings: ReadonlyArray, ...properties: Raw[]): StyleD } } -function css(strings: ReadonlyArray, ...properties: Exclude, Expression>[]): CSS { +function css(strings: ReadonlyArray, ...properties: Exclude, Expression>[]): CSS { const style: Style = [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 } } -function insert(sheet: Sheet, definition: StyleDefinition, props: Arguments): string | null { +function insert(sheet: Sheet, definition: StyleDefinition, props: Arguments): string | null { const { styles, type } = definition const { css, definitions } = compile(styles, props) const compiledId = hash(css) @@ -120,5 +120,5 @@ function insert(sheet: Sheet, definition: StyleDefinition return null } -export type { Arguments, Compiler, CreateCallback, CSS, DefaultTheme, Properties, Sheet, Style, StyleDefinition, TeilerComponent, HTMLElements } +export type { Arguments, Compiler, CreateCallback, CSS, DefaultTheme, Properties, Raw, Sheet, Style, StyleDefinition, TeilerComponent, HTMLElements } export { component, css, global, insert, keyframes, styled } diff --git a/packages/core/src/css.test.ts b/packages/core/src/css.test.ts index 2e62a8c..45f11c8 100644 --- a/packages/core/src/css.test.ts +++ b/packages/core/src/css.test.ts @@ -127,7 +127,7 @@ describe('compile', () => { }) test('with css', () => { - const css: CSS = { + const css: CSS<{}> = { id: 't1vxhd59', styles: [[['background: ', ';'], ['red']]], __css__: true, diff --git a/packages/core/src/css.ts b/packages/core/src/css.ts index bc213d1..70db723 100644 --- a/packages/core/src/css.ts +++ b/packages/core/src/css.ts @@ -1,4 +1,4 @@ -import type { Arguments, HTMLElements } from './constructor' +import type { Arguments, HTMLElements, Raw } from './constructor' import type { Pattern, Style, StyleDefinition } from '.' import { middleware, prefixer, rulesheet, serialize, stringify, compile as stylisCompile } from 'stylis' @@ -11,10 +11,10 @@ type CompileResult = { } function compile(styles: Array>, props: Arguments): CompileResult { - return styles.reduce( + return styles.reduce>( (result, [strings, properties]) => { const compiled = strings - .reduce((acc, strings, index) => { + .reduce<(string | true | Raw)[]>((acc, strings, index) => { acc = [...acc, strings] const property = properties.at(index) @@ -67,7 +67,7 @@ function compile(styles: Array>, props: Arguments): C } function transpile(css: string): string { - const results = [] + const results: string[] = [] serialize( stylisCompile(css), diff --git a/packages/core/src/pattern.test.ts b/packages/core/src/pattern.test.ts index 8a4538d..a7d43c9 100644 --- a/packages/core/src/pattern.test.ts +++ b/packages/core/src/pattern.test.ts @@ -57,13 +57,13 @@ describe('pattern', () => { }) }) -type TestComponent = TeilerComponent & { +type TestComponent = TeilerComponent & { render(): string } const sheet = createStyleSheet({}) -const createComponent = (styles: StyleDefinition): TestComponent => { +const createComponent = (styles: StyleDefinition): TestComponent => { return { styleDefinition: styles, render() { diff --git a/packages/core/src/pattern.ts b/packages/core/src/pattern.ts index d5dc53f..543e9b6 100644 --- a/packages/core/src/pattern.ts +++ b/packages/core/src/pattern.ts @@ -6,29 +6,29 @@ import hash from './hash' type PropertiesWithPattern = Properties | Pattern -type Pattern = { +type Pattern = { styles: Style[] tag: Target id: string __pattern__: true } -type ExtendCallback = (string: ReadonlyArray, ...properties: Properties>[]) => Pattern> +type ExtendCallback = (string: ReadonlyArray, ...properties: Properties>[]) => Pattern> -type Constructor = { - (pattern: Pattern): ExtendCallback - (string: ReadonlyArray, ...properties: PropertiesWithPattern[]): Pattern +type Constructor = { + (pattern: Pattern): ExtendCallback + (string: ReadonlyArray, ...properties: PropertiesWithPattern[]): Pattern } -type ConstructorWithTags = Constructor<'div'> & { [K in HTMLElements]: Constructor } & { global: Constructor } - type Infer = Component extends Pattern ? P & Props : Props -const construct = (tag: HTMLElements) => { - return (stringOrPattern: Pattern | ReadonlyArray, ...properties: Properties[]): Pattern | ExtendCallback => { +const construct = (tag: Target) => { + function create(stringOrPattern: Pattern): ExtendCallback + function create(stringOrPattern: ReadonlyArray, ...properties: PropertiesWithPattern[]): Pattern + function create(stringOrPattern: Pattern | ReadonlyArray, ...properties: Properties[]): Pattern | ExtendCallback { if ('__pattern__' in stringOrPattern) { return (strings: ReadonlyArray, ...properties: Properties>[]) => { - const style: Style = [Array.from(strings), properties] + const style: Style> = [Array.from(strings), properties] const styles = [...stringOrPattern.styles, style] const id = styles.reduce((acc, [strings]) => acc + strings.join(''), '') return { styles: styles, id: 't' + hash(id), tag: stringOrPattern.tag, __pattern__: true } @@ -41,18 +41,23 @@ const construct = (tag: HTMLElements) => { return { styles: styles, id: 't' + hash(id), tag, __pattern__: true } } } + + return create } -const pattern = construct('div') +type HTMLElementsWithoutNull = Exclude +type ConstructorWithTags = Constructor<'div'> & { [K in HTMLElementsWithoutNull]: Constructor } & { global: Constructor } + +const pattern = construct('div') as ConstructorWithTags tags.forEach((tag) => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error pattern[tag] = construct(tag) }) pattern['global'] = construct(null) -const binded = pattern as ConstructorWithTags - type CreateCallback, Props> = (styles: StyleDefinition) => Type function sew>(pattern: Pattern, createComponent: CreateCallback): Type { @@ -64,5 +69,5 @@ function sew { }) describe('createStyleSheet SSR', () => { - beforeAll(() => (global.document = undefined)) + beforeAll(() => (global.document = undefined!)) test('should create a new StyleSheet object', () => { const sheet = createStyleSheet({}) diff --git a/packages/core/src/sheet/tag.ts b/packages/core/src/sheet/tag.ts index 4a72fcd..6e778d0 100644 --- a/packages/core/src/sheet/tag.ts +++ b/packages/core/src/sheet/tag.ts @@ -1,7 +1,7 @@ type Tag = { insertRule(key: string, rule: string): number deleteRule(key: string): void - getRule(key: string): string + getRule(key: string): string | null getAllRules(): string getAllKeys(): string[] [k: string]: unknown @@ -55,7 +55,7 @@ export function createBrowserTag(container?: HTMLElement): Tag { return inserted.size }, deleteRule: function (key: string): void { - rules.removeChild(inserted.get(key)) + rules.removeChild(inserted.get(key)!) inserted.delete(key) }, getRule: function (key: string): string | null { diff --git a/packages/core/src/tags.ts b/packages/core/src/tags.ts index 32ad1e4..1db360b 100644 --- a/packages/core/src/tags.ts +++ b/packages/core/src/tags.ts @@ -131,5 +131,5 @@ const elements = [ 'text', ] as const -export default new Set(elements) -export type HTMLElements = (typeof elements)[number] +export default elements +export type HTMLElements = (typeof elements)[number] | null diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index c3c8fa0..1776826 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -8,7 +8,7 @@ "importHelpers": true, "moduleResolution": "node", "experimentalDecorators": true, - "strict": false, + "strict": true, "strictPropertyInitialization": false, "sourceMap": true, "allowSyntheticDefaultImports": true, diff --git a/packages/svelte/src/Styled.svelte b/packages/svelte/src/Styled.svelte index 3e85f88..d80fb41 100644 --- a/packages/svelte/src/Styled.svelte +++ b/packages/svelte/src/Styled.svelte @@ -1,4 +1,11 @@