-
Notifications
You must be signed in to change notification settings - Fork 81
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
ci: Fix build not including typescript types #2076
Conversation
|
export { ModalToggleButton } from './components/Modal/ModalToggleButton' | ||
export { ModalOpenLink } from './components/Modal/ModalOpenLink' | ||
export { ModalHeading } from './components/Modal/ModalHeading/ModalHeading' | ||
export { ModalFooter } from './components/Modal/ModalFooter/ModalFooter' | ||
export type { ModalProps, ModalRef } from './components/Modal/Modal' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These export type
changes silence some TS warnings we were getting on build
@@ -11,11 +11,12 @@ | |||
"module": "esnext", | |||
"moduleResolution": "node", | |||
"resolveJsonModule": true, | |||
"noEmit": true, | |||
"emitDeclarationOnly": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, awesome-typescript-loader
was exporting the types. Now we rely on tsc to do it, so we emit those type declarations only, and let babel emit the rest of the transpiled source code
"jsx": "react", | ||
"noImplicitAny": true, | ||
"declaration": true, | ||
"outDir": "./lib" | ||
"outDir": "./lib", | ||
"isolatedModules": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"build": "tsc && webpack --progress", | ||
"build:watch": "tsc && webpack --watch", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually call tsc
here so that types are built to lib
"lint": "tsc --noEmit && eslint --ext js,jsx,ts,tsx src && stylelint \"src/**/*.{css,scss}\"", | ||
"build": "tsc && webpack --progress", | ||
"build:watch": "tsc && webpack --watch", | ||
"lint": "tsc --noEmit --emitDeclarationOnly false && eslint --ext js,jsx,ts,tsx src && stylelint \"src/**/*.{css,scss}\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noEmit
cannot be used alongside emitDeclarationOnly
(as of ts 3.8), which is now in tsconfig. So we have to set it to false here, which is the recommended workaround
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tentatively looks good to me... how can we check that this fixes the problem?
The |
Summary
Looks like when the TS version was bumped, the refactor to remove
awesome-typescript-loader
and rely purely on babel didn't backfilll for type generation which babel does not do on its own. In this PR we manually calltsc
in the build step and let it emit the type declarations. This is the recommended approach for projects using babel alone and not relying on ts-loader.Alternative considered: use ts loader on ts|x files before running babel. ts-loader is a bit slow, and felt like a more repetitive solution, using two loaders on all of our ts/tsx files when
tsc
will directly create just the type exports for us without any additional config.Resources:
Related Issues or PRs
closes: #2053
stems from: #1548
How To Test
Checkout the code, clean your local files (delete node_modules and lib), freshly install packages with yarn. running
yarn
will also runyarn build
which will create the lib directory where you can confirm that .d.ts files are now output correctly again. Runningyarn pack
will generate the tarball which you can also verify includes the types.Screenshots (optional):