From 9563ce7e78951a71e91138807759e3c438d41cef Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 12 Oct 2022 20:37:32 +0200 Subject: [PATCH] more typesafe CSF3 types for svelte --- code/addons/highlight/package.json | 6 +- code/lib/core-common/src/index.ts | 1 + .../core-common/src/utils/satisfies.ts} | 0 code/package.json | 7 +- code/renderers/react/package.json | 1 - .../react/src/__test__/CSF3.test.tsx | 9 +- code/renderers/svelte/package.json | 6 +- .../svelte/src/___test___/Button.svelte | 12 + .../svelte/src/___test___/CSF3.test.ts | 226 ++++++++++++++++++ .../svelte/src/___test___/Decorator.svelte | 8 + .../svelte/src/___test___/Decorator2.svelte | 8 + .../svelte/src/docs/extractArgTypes.test.ts | 1 + .../svelte/src/docs/extractArgTypes.ts | 2 +- .../docs/extractComponentDescription.test.ts | 1 + .../svelte/src/docs/sourceDecorator.test.ts | 7 +- .../svelte/src/docs/sourceDecorator.ts | 2 +- code/renderers/svelte/src/globals.ts | 1 - code/renderers/svelte/src/public-types.ts | 55 ++++- code/renderers/svelte/src/render.ts | 9 +- code/renderers/svelte/src/types.ts | 36 ++- code/renderers/svelte/src/typings.d.ts | 4 +- .../svelte/template/components/Button.svelte | 2 +- .../svelte/template/components/index.js | 12 +- .../svelte/templates/PreviewRender.svelte | 9 +- .../svelte/templates/SlotDecorator.svelte | 1 + code/renderers/svelte/tsconfig.json | 4 +- code/yarn.lock | 74 +++--- package.json | 3 +- scripts/tasks/check.ts | 2 +- 29 files changed, 417 insertions(+), 92 deletions(-) rename code/{renderers/react/src/__test__/utils.ts => lib/core-common/src/utils/satisfies.ts} (100%) create mode 100644 code/renderers/svelte/src/___test___/Button.svelte create mode 100644 code/renderers/svelte/src/___test___/CSF3.test.ts create mode 100644 code/renderers/svelte/src/___test___/Decorator.svelte create mode 100644 code/renderers/svelte/src/___test___/Decorator2.svelte diff --git a/code/addons/highlight/package.json b/code/addons/highlight/package.json index dad00fa7e4db..92a6e14cea96 100644 --- a/code/addons/highlight/package.json +++ b/code/addons/highlight/package.json @@ -58,15 +58,15 @@ "@types/webpack-env": "^1.16.0", "typescript": "~4.6.3" }, + "publishConfig": { + "access": "public" + }, "bundler": { "entries": [ "./src/index.ts", "./src/highlight.ts" ] }, - "publishConfig": { - "access": "public" - }, "gitHead": "438114fcf62a763f0e8c07e2c34890dd987ca431", "sbmodern": "dist/modern/index.js", "storybook": { diff --git a/code/lib/core-common/src/index.ts b/code/lib/core-common/src/index.ts index 5b95a7716571..034c4a9301c6 100644 --- a/code/lib/core-common/src/index.ts +++ b/code/lib/core-common/src/index.ts @@ -28,6 +28,7 @@ export * from './utils/normalize-stories'; export * from './utils/readTemplate'; export * from './utils/findDistEsm'; export * from './utils/symlinks'; +export * from './utils/satisfies'; export * from './types'; diff --git a/code/renderers/react/src/__test__/utils.ts b/code/lib/core-common/src/utils/satisfies.ts similarity index 100% rename from code/renderers/react/src/__test__/utils.ts rename to code/lib/core-common/src/utils/satisfies.ts diff --git a/code/package.json b/code/package.json index fc972e5f977e..fb1d8add2da6 100644 --- a/code/package.json +++ b/code/package.json @@ -111,6 +111,7 @@ ], "resolutions": { "@nrwl/cli": "14.6.1", + "@storybook/csf": "portal:/Users/kasperpeulen/code/storybook/csf", "@typescript-eslint/eslint-plugin": "^5.15.0", "@typescript-eslint/experimental-utils": "5.3.0", "@typescript-eslint/parser": "^5.15.0", @@ -336,7 +337,8 @@ "ts-jest": "^26.4.4", "ts-node": "^10.4.0", "tsup": "^6.2.2", - "typescript": "4.7.4", + "type-fest": "2.19.0", + "typescript": "~4.6.3", "util": "^0.12.4", "vite": "^3.1.7", "wait-on": "^5.2.1", @@ -346,6 +348,9 @@ "window-size": "^1.1.1", "zx": "^7.0.3" }, + "devDependencies": { + "expect-type": "^0.14.2" + }, "dependenciesMeta": { "@compodoc/compodoc": { "built": false diff --git a/code/renderers/react/package.json b/code/renderers/react/package.json index ae3c052755f8..68049a8d6747 100644 --- a/code/renderers/react/package.json +++ b/code/renderers/react/package.json @@ -76,7 +76,6 @@ "@babel/core": "^7.11.5", "@jest/globals": "^26.6.2", "@types/util-deprecate": "^1.0.0", - "expect-type": "^0.14.2", "jest-specific-snapshot": "^4.0.0", "require-from-string": "^2.0.2", "typescript": "~4.6.3" diff --git a/code/renderers/react/src/__test__/CSF3.test.tsx b/code/renderers/react/src/__test__/CSF3.test.tsx index 89bbb79aa3ea..94a73fee27bc 100644 --- a/code/renderers/react/src/__test__/CSF3.test.tsx +++ b/code/renderers/react/src/__test__/CSF3.test.tsx @@ -1,12 +1,11 @@ -import React, { KeyboardEventHandler, ReactNode } from 'react'; -import { expectTypeOf } from 'expect-type'; import { describe, test } from '@jest/globals'; +import { satisfies } from '@storybook/core-common'; import { StoryAnnotations } from '@storybook/csf'; +import { expectTypeOf } from 'expect-type'; +import React, { KeyboardEventHandler, ReactNode } from 'react'; import { SetOptional } from 'type-fest'; - -import { Meta, StoryObj } from '../public-types'; import { DecoratorFn } from '../public-api'; -import { satisfies } from './utils'; +import { Meta, StoryObj } from '../public-types'; import { ReactFramework } from '../types'; type ReactStory = StoryAnnotations; diff --git a/code/renderers/svelte/package.json b/code/renderers/svelte/package.json index ace782a2c08d..5a9a28bf74de 100644 --- a/code/renderers/svelte/package.json +++ b/code/renderers/svelte/package.json @@ -50,7 +50,7 @@ "*.d.ts" ], "scripts": { - "check": "../../../scripts/node_modules/.bin/tsc --noEmit", + "check": "svelte-check --tsconfig ./tsconfig.json", "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { @@ -63,10 +63,12 @@ "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", - "sveltedoc-parser": "^4.2.1" + "sveltedoc-parser": "^4.2.1", + "type-fest": "2.19.0" }, "devDependencies": { "svelte": "^3.31.2", + "svelte-check": "^2.9.2", "typescript": "~4.6.3" }, "peerDependencies": { diff --git a/code/renderers/svelte/src/___test___/Button.svelte b/code/renderers/svelte/src/___test___/Button.svelte new file mode 100644 index 000000000000..b7fd6e8e325c --- /dev/null +++ b/code/renderers/svelte/src/___test___/Button.svelte @@ -0,0 +1,12 @@ + + + diff --git a/code/renderers/svelte/src/___test___/CSF3.test.ts b/code/renderers/svelte/src/___test___/CSF3.test.ts new file mode 100644 index 000000000000..84cc18481ea3 --- /dev/null +++ b/code/renderers/svelte/src/___test___/CSF3.test.ts @@ -0,0 +1,226 @@ +import { describe, test } from '@jest/globals'; +import { satisfies } from '@storybook/core-common'; +import { ComponentAnnotations, StoryAnnotations } from '@storybook/csf'; +import { expectTypeOf } from 'expect-type'; +import { ComponentProps, SvelteComponentTyped } from 'svelte'; + +import { DecoratorFn, Meta, StoryObj } from '../public-types'; +import { SvelteFramework } from '../types'; +import Button from './Button.svelte'; +import Decorator from './Decorator.svelte'; +import Decorator2 from './Decorator2.svelte'; + +type SvelteStory = StoryAnnotations< + SvelteFramework, + Args, + RequiredArgs +>; + +describe('Meta', () => { + test('Generic parameter of Meta can be a component', () => { + const meta: Meta