Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to TS5.0 #21792

Closed
shilman opened this issue Mar 28, 2023 · 15 comments · Fixed by #24175
Closed

Upgrade to TS5.0 #21792

shilman opened this issue Mar 28, 2023 · 15 comments · Fixed by #24175
Labels
maintenance User-facing maintenance tasks

Comments

@shilman
Copy link
Member

shilman commented Mar 28, 2023

Long term, we'll want to:

  • Upgrade storybook's monorepo to TypeScript 5 (this is a maintenance task)
  • Ensure storybook is compatible with 5.0.0 and the generators we're compatible with (this will sort of happen automatically because generators will publish new versions and we'll start using them after ~24h)
  • Maybe add an internal sandbox to test compatibility with TypeScript 5, but I'm not sure there's a need for this.
  • Maybe investigate if the new language features might be useful for storybook or it's users.

Originally posted by @ndelangen in #21276 (comment)

@psychobolt
Copy link

psychobolt commented May 3, 2023

For anyone who wants to use multiple array extends feature in TS 5.0, you'll get a error when running storybook build, sb automigrate, or storybook dev

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Array

Issue was fixed in dividab/tsconfig-paths#245 , but is still a issue until we can upgrade esbuild-register (egoist/esbuild-register#91) with the fix. I managed to set a resolution with the precompiled package update in my project. https://github.com/psychobolt/vite-storybook-boilerplate/tree/main/packages/esbuild-register

  "resolutions": {
    "esbuild-register": "workspace:*"
  }

@naporin0624
Copy link
Contributor

I applied the following patch in patch-package and it worked!

https://gist.github.com/naporin0624/70c2e00f791d881895910a8f2cdb3026

@matthew-dean
Copy link

Storybook 7 for Vite does not yet support TypeScript 5 (specifically the satisfies keyword). It has an old dependency on vue-docgen-api.

I was able to fix this by overriding Storybook in my package.json:

  "overrides": {
    "vue-docgen-api": "^4.73.0"
  },

@custardcream98
Copy link

custardcream98 commented Sep 2, 2023

I'm still waiting for esbuild-register to be updated, but it seems like that won't happen anytime soon, as there haven't been any releases for esbuild-register since last year.

I believe it would be a good idea to explore alternative options if available. It's frustrating that Storybook still doesn't support array extends!

@shilman
Copy link
Member Author

shilman commented Sep 2, 2023

@custardcream98 what isn't working for you? Do you have a reproduction you can share? This issue is about updating the storybook monorepo to TS5. I'm pretty sure it should work fine in user projects (but have not verified--I'm on my phone)

@custardcream98
Copy link

@shilman
Yes, it works fine but I can't use array extends in tsconfig as described above.

@shilman
Copy link
Member Author

shilman commented Sep 2, 2023

@custardcream98 gotcha--thanks for clarifying

@ndelangen
Copy link
Member

@kasperpeulen this is now no longer blocked by esbuild-register

@shilman
Copy link
Member Author

shilman commented Oct 4, 2023

@custardcream98 does this now work in 7.5.0-alpha.3 and above for you?

@steven-prybylynskyi
Copy link

I have an error when using the mentioned above satisifies keyword

ModuleBuildError: Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /SelectControl.stories.tsx: Unexpected token, expected "," (18:2)

  16 |     placeholder: 'Estimated Arrival Time'
  17 |   }
> 18 | } satisfies Meta<typeof SelectControlComponent>);
     |   ^
  19 | export default meta;
  20 | type Story = StoryObj<typeof meta>;
  21 | export const SelectControl: Story = {
    at constructor (/node_modules/@babel/parser/lib/index.js:356:19)
    at JSXParserMixin.raise (/node_modules/@babel/parser/lib/index.js:3223:19)
    at JSXParserMixin.unexpected (/node_modules/@babel/parser/lib/index.js:3253:16)
    at JSXParserMixin.expect (/node_modules/@babel/parser/lib/index.js:3590:28)
    at JSXParserMixin.parseParenAndDistinguishExpression (/node_modules/@babel/parser/lib/index.js:11490:14)
    at JSXParserMixin.parseExprAtom (/node_modules/@babel/parser/lib/index.js:11142:23)
    at JSXParserMixin.parseExprAtom (/node_modules/@babel/parser/lib/index.js:6937:20)
    at JSXParserMixin.parseExprSubscripts (/node_modules/@babel/parser/lib/index.js:10862:23)
    at JSXParserMixin.parseUpdate (/node_modules/@babel/parser/lib/index.js:10845:21)
    at JSXParserMixin.parseMaybeUnary (/node_modules/@babel/parser/lib/index.js:10821:23)
    at JSXParserMixin.parseMaybeUnaryOrPrivate (/node_modules/@babel/parser/lib/index.js:10659:61)
    at JSXParserMixin.parseExprOps (/node_modules/@babel/parser/lib/index.js:10664:23)
    at JSXParserMixin.parseMaybeConditional (/node_modules/@babel/parser/lib/index.js:10641:23)
    at JSXParserMixin.parseMaybeAssign (/node_modules/@babel/parser/lib/index.js:10602:21)
    at /node_modules/@babel/parser/lib/index.js:10572:39
    at JSXParserMixin.allowInAnd (/node_modules/@babel/parser/lib/index.js:12284:16)
    at JSXParserMixin.parseMaybeAssignAllowIn (/node_modules/@babel/parser/lib/index.js:10572:17)
    at JSXParserMixin.parseVar (/node_modules/@babel/parser/lib/index.js:13264:91)
    at JSXParserMixin.parseVarStatement (/node_modules/@babel/parser/lib/index.js:13105:10)
    at JSXParserMixin.parseStatementContent (/node_modules/@babel/parser/lib/index.js:12688:23)
    at JSXParserMixin.parseStatementLike (/node_modules/@babel/parser/lib/index.js:12593:17)
    at JSXParserMixin.parseModuleItem (/node_modules/@babel/parser/lib/index.js:12570:17)
    at JSXParserMixin.parseBlockOrModuleBlockBody (/node_modules/@babel/parser/lib/index.js:13194:36)
    at JSXParserMixin.parseBlockBody (/node_modules/@babel/parser/lib/index.js:13187:10)
    at JSXParserMixin.parseProgram (/node_modules/@babel/parser/lib/index.js:12469:10)
    at JSXParserMixin.parseTopLevel (/node_modules/@babel/parser/lib/index.js:12459:25)
    at JSXParserMixin.parse (/node_modules/@babel/parser/lib/index.js:14381:10)
    at parse (/node_modules/@babel/parser/lib/index.js:14422:38)
    at parser (/node_modules/@babel/core/lib/parser/index.js:41:34)
    at parser.next (<anonymous>)
    at normalizeFile (/node_modules/@babel/core/lib/transformation/normalize-file.js:64:37)
    at normalizeFile.next (<anonymous>)
    at run (/node_modules/@babel/core/lib/transformation/index.js:21:50)
    at run.next (<anonymous>)
    at transform (/node_modules/@babel/core/lib/transform.js:22:33)
    at transform.next (<anonymous>)
    at step (/node_modules/gensync/index.js:261:32)
    at /node_modules/gensync/index.js:273:13
    at async.call.result.err.err (/node_modules/gensync/index.js:223:11)
    at processResult (/node_modules/webpack/lib/NormalModule.js:764:19)
    at /node_modules/webpack/lib/NormalModule.js:866:5
    at /node_modules/loader-runner/lib/LoaderRunner.js:400:11
    at /node_modules/loader-runner/lib/LoaderRunner.js:252:18
    at context.callback (/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /node_modules/babel-loader/lib/index.js:39:103

@steven-prybylynskyi
Copy link

tsconfig:

{
  "compilerOptions": {
    "baseUrl": ".",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    "jsx": "react-jsx",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "noImplicitThis": false,
    "paths": {
      "@/*": ["src/*"]
    },
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "strictNullChecks": true,
    "target": "esnext"
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules",
    "dist",
    "**/*.stories.{ts,tsx}"
  ],
  "ts-node": {
    "compilerOptions": {
      "module": "CommonJS"
    }
  }
}

@steven-prybylynskyi
Copy link

package.json:

{
  "scripts": {
    "storybook": "storybook dev -p 6006",
  },
  "license": "MIT",
  "dependencies": {
    "date-fns": "^2.30.0",
    "lodash": "^4.17.21",
    "react": "^18.2.0",
    "react-datepicker": "^4.20.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.47.0",
    "react-icons": "^4.11.0",
    "react-router-dom": "^6.16.0"
  },
  "devDependencies": {
    "@storybook/addon-essentials": "^7.4.6",
    "@storybook/addon-interactions": "^7.4.6",
    "@storybook/jest": "^0.2.3",
    "@storybook/react": "^7.4.6",
    "@storybook/react-webpack5": "^7.4.6",
    "@storybook/testing-library": "^0.2.2",
    "@types/webpack": "^5.28.3",
    "clean-webpack-plugin": "^4.0.0",
    "css-loader": "^6.8.1",
    "dotenv-defaults": "^5.0.2",
    "external-remotes-plugin": "^1.0.0",
    "husky": "^8.0.3",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "jest-extended": "^4.0.2",
    "miragejs": "^0.1.47",
    "react-test-renderer": "^18.2.0",
    "storybook": "^7.4.6",
    "style-loader": "^3.3.3",
    "ts-jest": "^29.1.1",
    "ts-loader": "^9.5.0",
    "ts-node": "^10.9.1",
    "typescript": "~5.0.4",
    "webpack": "^5.88.2",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^4.15.1",
    "webpack-merge": "^5.9.0"
  },
  "eslintConfig": {
    "overrides": [
      {
        "files": [
          "*.stories.tsx"
        ],
        "rules": {
          "import/no-extraneous-dependencies": "off",
          "react-hooks/rules-of-hooks": "off"
        }
      }
    ]
  },
}

@steven-prybylynskyi
Copy link

.storybook/main.ts

import { StorybookConfig } from '@storybook/react-webpack5';

const storybookConfig: StorybookConfig = {
  stories: ['../src'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions'
  ],
  framework: {
    name: '@storybook/react-webpack5',
    options: {},
  },
  docs: {
    autodocs: true,
  },
  features: {
    buildStoriesJson: true,
  },
}

export default storybookConfig;

@steven-prybylynskyi
Copy link

@shilman please let me know where should I look at?

@steven-prybylynskyi
Copy link

also that:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants