adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Can't compile with TypeScript out of the box

Open alecgibson opened this issue 2 years ago • 8 comments

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

To Reproduce Steps to reproduce the behavior:

  1. Set up a new TypeScript project with the above dependencies, following the docs for setup
  2. 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"]
  }
}

alecgibson avatar Feb 15 '22 12:02 alecgibson

(Even if this gets marked as wontfix, I thought I'd at least document something somewhere in case anyone else runs into this)

alecgibson avatar Feb 15 '22 12:02 alecgibson

I am having the same issue, 170 errors from TypeScript types

LukeXF avatar Mar 04 '22 18:03 LukeXF

We will likely create a CLI similar to 'create-react-app' in the future. For now I'm leaving this open

dziraf avatar Jun 15 '22 11:06 dziraf

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...

uilyam avatar Jun 17 '22 13:06 uilyam

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?

EduardoBautista avatar Jun 29 '22 16:06 EduardoBautista

Have just bumped to v6 and had to add @types/react-text-mask on top of existing dependencies.

alecgibson avatar Aug 02 '22 14:08 alecgibson

@alecgibson can you share your tsconfig? I'm not getting any type errors in our demo apps but we might have different tsconfigs

dziraf avatar Aug 02 '22 17:08 dziraf

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])

alecgibson avatar Aug 09 '22 08:08 alecgibson

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

Screen Shot 2023-02-07 at 9 42 19 PM

chadybadour avatar Feb 07 '23 19:02 chadybadour

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.

dziraf avatar Apr 18 '23 13:04 dziraf