Why do I get TS Errors in material/web itself during compilation? #5564
-
So I use material-web as a bundled JS library. Because our project is in TypeScript (no modules though) I imported/exported all the js files in my "...d.ts" file like in "all.d.ts". But now the TS compiler follows those paths and find several errors which are true in my opinion. E.g. What do I not understand? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Can you provide more info with your project and build setup, such as a codepen or github repo? I'm not sure what no modules in TypeScript means, and importing |
Beta Was this translation helpful? Give feedback.
-
Ok, I can't really provide it somewhere, but I'll try to explain. We use TypeScript, but because we have a lot of legacy JS code with global variables etc., we can't use any module system yet. As soon as I type "import" or "export" somewhere, the whole project becomes modulized and I have to do it correctly for thousands of files.
I also tried to create a bundled "d.ts." file with tools like "tsup". The tool resolves the paths in the "all.d.ts" file and puts all the contents in one file, so I have all the "declare..." statements in one file. But then there are the same errors in this file... My solution is to ignore them with @ts-ignore, but I don't understand why they are there in the first place...? |
Beta Was this translation helpful? Give feedback.
-
They are kind of related. skipLibCheck helps, but it's a bad option as it could ignore some other errors during compilation too. Types aside, what about the error itself? It seems like "type" is actually optional in "Dialog" class and required in "LitElement"? |
Beta Was this translation helpful? Give feedback.
I think this is the same issue as #5129. It's not very well supported to try and bundle published
.d.ts
files from an npm module.It sounds like the way your project is set up, TypeScript is trying to compile
node_modules/@material/web/
. You could try usingskipLibCheck
to see if that changes anything.Otherwise, if you really need to build the project through TypeScript all the way, you can
git clone
the entire repository rather than usingnpm install @material/web
. That will give you the original TypeScript files to include with your build system, rather than using the pre-built published.js
files.