Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/lib/cli-storybook/src/sandbox-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const baseTemplates = {
},
modifications: {
useCsfFactory: true,
extraDependencies: ['prop-types'],
extraDependencies: ['prop-types', '@types/prop-types'],
mainConfig: {
features: {
developmentModeForBuild: true,
Expand Down
3 changes: 2 additions & 1 deletion code/renderers/react/template/stories/csf4.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-expect-error this will be part of the package.json of the sandbox
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- we can't expect error as it is an error in development but it isn't sandbox
// @ts-ignore only present in sandbox
import preview from '#.storybook/preview';

const meta = preview.meta({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const Context: StoryObj<typeof Component> = {
</TestContext.Provider>
),
],
render: function Render(args, context) {
render: function Render() {
const value = useContext(TestContext);

if (!value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ interface IBProps {
}

/** A component */
const A = (props: IAProps): JSX.Element => {
const A = (props: IAProps): React.JSX.Element => {
return <>Hi {props.aProperty}</>;
};

/** B component */
const B = (props: IBProps): JSX.Element => {
const B = (props: IBProps): React.JSX.Element => {
return <>Hi {props.bProperty}</>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface Props {
margin: number;
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- we can't expect error as it isn't an error in development but it is in sandbox
// @ts-ignore unused props
export const Text: React.FC<Props> = ({ padding = '0', margin }) => <>Text</>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using underscore prefix for unused parameters (_padding, _margin) as a TypeScript convention instead of ts-ignore, which would be more explicit about intentional non-usage

Suggested change
export const Text: React.FC<Props> = ({ padding = '0', margin }) => <>Text</>;
export const Text: React.FC<Props> = ({ padding: _padding = '0', margin: _margin }) => <>Text</>;


export const component = Text;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const Paragraph: React.FC<ElemBProps> = ({ size, children }) => (
<div className={size}>{children}</div>
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- we can't expect error as it isn't an error in 18 (development) but it is in 19 (sandbox)
// @ts-ignore not present on react 19
Paragraph.defaultProps = { size: 'md' };

export const component = Header;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface IProps {
color?: string;
}

const iconButton: FC<IProps> = function IconButton(props) {
const iconButton: FC<IProps> = function IconButton() {
return <div className="icon-button">icon-button</div>;
};

Expand All @@ -17,6 +17,8 @@ iconButton.propTypes = {
color: PropTypes.string,
};

// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- we can't expect error as it isn't an error in 18 (development) but it is in 19 (sandbox)
// @ts-ignore not present on react 19
iconButton.defaultProps = {
color: 'primary',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import { imported } from '../imported';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore (css import not supported in TS)
import * as styles from '../imported.module.css';
import styles from '../imported.module.css';

const local = 'local-value';

Expand Down Expand Up @@ -37,6 +37,8 @@ export const PropsWriter: React.FC<PropsWriterProps> = (props: PropsWriterProps)
<pre>{JSON.stringify(props)}</pre>
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- we can't expect error as it isn't an error in 18 (development) but it is in 19 (sandbox)
// @ts-ignore not present on react 19
PropsWriter.defaultProps = {
numberOptional: 1,
stringOptional: 'stringOptional',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ interface TypeScriptPropsProps {
inlinedNumericLiteralUnion: 0 | 1 | 2;
}

export const TypeScriptProps: FC<TypeScriptPropsProps> = (props) => <div>TypeScript!</div>;
export const TypeScriptProps: FC<TypeScriptPropsProps> = () => <div>TypeScript!</div>;

This comment was marked as spam.


export const component = TypeScriptProps;
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ interface TypeScriptPropsProps {
}

export const TypeScriptProps: FC<TypeScriptPropsProps> = () => <div>TypeScript!</div>;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- we can't expect error as it isn't an error in 18 (development) but it is in 19 (sandbox)
// @ts-ignore not present on react 19
Comment on lines +96 to +97
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed, if we do #32406

TypeScriptProps.defaultProps = {
any: 'Any value',
string: 'A string value',
Expand Down
2 changes: 2 additions & 0 deletions scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { version } from '../code/package.json';
import { bench } from './tasks/bench';
import { build } from './tasks/build';
import { check } from './tasks/check';
import { checkSandbox } from './tasks/check-sandbox';
import { chromatic } from './tasks/chromatic';
import { compile } from './tasks/compile';
import { dev } from './tasks/dev';
Expand Down Expand Up @@ -91,6 +92,7 @@ export const tasks = {
// These tasks pertain to a single sandbox in the ../sandboxes dir
generate,
sandbox,
'check-sandbox': checkSandbox,
dev,
'smoke-test': smokeTest,
build,
Expand Down
24 changes: 24 additions & 0 deletions scripts/tasks/check-sandbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { access } from 'node:fs/promises';

import type { Task } from '../task';
import { exec } from '../utils/exec';

async function pathExists(path: string) {
try {
await access(path);
return true;
} catch {
return false;
}
}

export const checkSandbox: Task = {
description: 'Typecheck the a sandbox',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Typo: 'Typecheck the a sandbox' should be 'Typecheck a sandbox' or 'Typecheck the sandbox'

Suggested change
description: 'Typecheck the a sandbox',
description: 'Typecheck a sandbox',

Copy link
Contributor Author

@mrginglymus mrginglymus Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one I will give you

dependsOn: ['sandbox'],
async ready({ builtSandboxDir }) {
return pathExists(builtSandboxDir);
},
async run({ sandboxDir }, { dryRun, debug }) {
await exec(`yarn typecheck`, { cwd: sandboxDir }, { dryRun, debug });
},
};
27 changes: 27 additions & 0 deletions scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export const init: Task['run'] = async (
case '@storybook/angular':
await prepareAngularSandbox(cwd, template.name);
break;
case '@storybook/react-vite':
await prepareViteSandbox(cwd);
break;
default:
}

Expand Down Expand Up @@ -878,6 +881,30 @@ async function prepareReactNativeWebSandbox(cwd: string) {
}
}

async function prepareViteSandbox(cwd: string) {
const packageJsonPath = join(cwd, 'package.json');
const packageJson = await readJson(packageJsonPath);

packageJson.scripts = {
...packageJson.scripts,
typecheck: 'yarn tsc -p tsconfig.app.json',
};
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));

const tsConfigPath = join(cwd, 'tsconfig.app.json');
const tsConfigContent = await readFile(tsConfigPath, { encoding: 'utf-8' });
// This does not preserve comments, but that shouldn't be an issue for sandboxes
const tsConfigJson = JSON5.parse(tsConfigContent);

// We use enums
tsConfigJson.compilerOptions.erasableSyntaxOnly = false;
// Lots of unnecessary imports of react that need fixing
tsConfigJson.compilerOptions.noUnusedLocals = false;
// Means we can check our own public types
tsConfigJson.compilerOptions.skipLibCheck = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Setting skipLibCheck to false may cause type errors from third-party packages. Consider documenting why this is necessary or if it should be conditional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shush greptile, that's the point! you managed to get that in your summary

also if there are type errors in the third-party packages we should be fixing them

await writeFile(tsConfigPath, JSON.stringify(tsConfigJson, null, 2));
}

async function prepareAngularSandbox(cwd: string, templateName: string) {
const angularJson = await readJson(join(cwd, 'angular.json'));

Expand Down
1 change: 1 addition & 0 deletions scripts/tasks/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const sandbox: Task = {
// Adding the dep makes sure that even npx will use the linked workspace version.
'@storybook/cli',
'lodash-es',
'@types/lodash-es',
'uuid',
];

Expand Down
1 change: 0 additions & 1 deletion scripts/utils/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export const addWorkaroundResolutions = async ({
'@testing-library/dom': '^9.3.4',
'@testing-library/jest-dom': '^6.6.3',
'@testing-library/user-event': '^14.5.2',
typescript: '~5.7.3',
rollup: '4.44.2',
};

Expand Down
Loading