adminjs
adminjs copied to clipboard
Can't compile with TypeScript out of the box
Describe the bug
Running tsc
out-of-the-box fails without installing additional @types/
packages.
Related:
- https://github.com/SoftwareBrothers/adminjs/issues/281
- https://github.com/SoftwareBrothers/adminjs/issues/611
- https://github.com/SoftwareBrothers/adminjs/issues/834
Installed libraries and their versions
- [email protected]
- @adminjs/[email protected]
- @adminjs/[email protected]
To Reproduce Steps to reproduce the behavior:
- Set up a new TypeScript project with the above dependencies, following the docs for setup
- Compile the TypeScript
Expected behavior
TypeScript compiles
Desktop (please complete the following information if relevant):
- OS: macOS 12.1
Additional context
This can be solved manually by running:
npm i --save-dev @types/express @types/express-session @types/flat @types/react-datepicker @types/react-redux @types/react-router @types/react-router-dom @types/styled-components @types/styled-system
However, doing this manually is:
- not very user-friendly, or obvious
- fragile, and may break if upstream type dependencies are changed
Note that you also need to tweak tsconfig.json
to include dom
types (although this isn't too surprising, given that React is being bundled):
{
"compilerOptions": {
"lib": ["dom"]
}
}
(Even if this gets marked as wontfix, I thought I'd at least document something somewhere in case anyone else runs into this)
I am having the same issue, 170 errors from TypeScript types
We will likely create a CLI similar to 'create-react-app' in the future. For now I'm leaving this open
This was really helpful, thank you! My nodemon
was obscuring what the exception was once I used the recommended fix it was back to working.
[nodemon] app crashed - waiting for file changes before starting...
AdminJS on its own won't compile. Open up https://github.com/SoftwareBrothers/adminjs/blob/master/src/frontend/components/property-type/reference/edit.tsx
And you will see a very simple issue.
https://github.com/SoftwareBrothers/adminjs/blob/master/src/frontend/components/property-type/reference/edit.tsx#L88
It's trying to assign a number
to a field that takes a boolean | undefined
. Are type errors ignored during development of AdminJS?
Have just bumped to v6 and had to add @types/react-text-mask
on top of existing dependencies.
@alecgibson can you share your tsconfig? I'm not getting any type errors in our demo apps but we might have different tsconfigs
Sorry about the delay. Here you are:
{
"include": [
"src/**/*",
"src/test/**/*"
],
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"importHelpers": true,
"noImplicitThis": true,
"noImplicitOverride": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "build",
"baseUrl": ".",
"lib": [
"dom",
"es2019"
],
"jsx": "react",
"types": [
"node",
"reflect-metadata",
"mocha",
"sinon",
"chai",
"chaiDom"
],
"paths": {
"@/*": ["src/*"]
}
}
}
Also as a sense-check, I've tried uninstalling the types again to check if this is still an issue, and it is. (Running [email protected]
)
I think i found it @alecgibson
importing any interface or class from the admin-bro or admin-js src folder will lead to automatically ts compile the admin-bro or Js directory in node modules. it is not an issue of tsconfig
We've updated Typescript version in all AdminJS packages with the release of version 7 and we're not seeing any type errors. If you're still experiencing type issues, please open a new issue or ping me to reopen this one.