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

Cannot find type definition file for 'types'. #1400

Closed
fveauvy opened this issue Oct 25, 2020 · 9 comments
Closed

Cannot find type definition file for 'types'. #1400

fveauvy opened this issue Oct 25, 2020 · 9 comments

Comments

@fveauvy
Copy link

fveauvy commented Oct 25, 2020

I wanted to try using typescript on a newly created Redwood project 0.20.0. I followed the guidance from the typescript page doc and created a page and a component (the component has been created with the --ts option).

I noticed this issue in the Problems tab of vs code.

Capture d’écran 2020-10-25 à 12 06 06

Capture d’écran 2020-10-25 à 12 06 30

@fveauvy
Copy link
Author

fveauvy commented Oct 26, 2020

Aside from the notification in the Problems tab, everything seems to be working fine.

I'll try to find why my IDE is displaying this "issue".

@thedavidprice
Copy link
Contributor

Hi @fveauvy welcome to Redwood! And a strange issue indeed.

@aldonline curious if you have any ideas here especially regarding how to get more information out of the VS Code output, e.g. where is "types" coming from?

@fveauvy
Copy link
Author

fveauvy commented Oct 26, 2020

Hello @thedavidprice ! Thanks for the warm welcome.

I'll try to investigate this issue myself this week, as I'd like to contribute to this awesome project :)

@thedavidprice
Copy link
Contributor

Rad! We'd welcome the help. There's some good "getting started as a contributor" info in this issue.

If you're interested in helping move TS support forward, here's the Project Board with Tracking issues.

And PR #1312 needs to be split into smaller PRs (see this comment). It might be a great place to start to ask if you could help move one of the specific items forward.

@fveauvy
Copy link
Author

fveauvy commented Oct 29, 2020

I think I found what was causing my issue.

microsoft/TypeScript#27956

In my case, the errors occurred because my package.json specified a package named @types/x. The notification in the Problems tab disappeared as soon as I removed the dependency from package.json.

@thedavidprice
Copy link
Contributor

Ah, rodger that. Doesn't look like there's a workaround for now, correct?

@fveauvy
Copy link
Author

fveauvy commented Oct 30, 2020

I think I found two workarounds by tweaking the tsconfig.json file a bit. But please keep in mind that I'm certainly not a typescript wizard and you should took it with a pinch of salt 😄

Let's say I add yup package (schema validation helper) as well as its typed package to the redwood web side :

  • yarn workspace web add yup
  • yarn workspace web add @types/yup -D

1. Add a types property

If I add the types property with an empty array value to tsconfig.json the issue isn't displayed anymore and I keep the type definition of yup in my IDE.

{
  "compilerOptions": {
    "noEmit": true,
    "allowJs": true,
    "esModuleInterop": true,
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "jsx": "preserve",
    "baseUrl": "./",
    "paths": {
      "src/*": ["./src/*"]
    },
    "typeRoots": ["../.redwood"],
    "types": []
  },
  "include": ["src"]
}

It's a bit odd since the types property doc mentions that only packages listed will be included in the global scope...

2. Modify the typeRoots property

Another workaround I found is to change the typeRoots property as followed :
"typeRoots": ["../.redwood", "../node_modules/@types"],

This makes more sense to me since I think that only adding ../.redwood is preventing other @types/. packages to be included.

@fveauvy fveauvy closed this as completed Oct 31, 2020
@jvanbaarsen
Copy link
Contributor

jvanbaarsen commented Nov 28, 2020

I'm still seeing this issue with Redwood 0.21. Can it be that no workaround has been pushed upstream? I only have this problem when I run yarn tsc -p ./api.

Can that have something to do with this note in the docs?
image

This is happening in a brand new project, only thing I've done after running the create-redwood app command is add the TSConfig files.

I'm having very few TS experience, so good chance I'm doing something stupid here.

@AntonioMeireles
Copy link
Contributor

@thedavidprice,

could we keep this open until a canonical solution is found ?

FWIW the "Modify the typeRoots property" referenced above doesn't seem to work at all. OTOH adding the empty types trick does make the error go away. It's not clear to me also if this is the right way to do it (as it seems at odds with MS docs - @Krisztiaan any idea on this ?); If it is then the tsconfig.json snippets at https://redwoodjs.com/docs/typescript.html#typescript should probably be updated so that things work of the box...

While on it, why doesn't yarn create redwood-app add those tsconfig.json by default ? less friction for users, IMHO.

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

No branches or pull requests

4 participants