-
Notifications
You must be signed in to change notification settings - Fork 40
ERROR in [default] \node_modules\angular2-logger\app\core\logger.ts:62:38 Type 'string' is not assignable to type 'Level'. #65
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
Comments
Hi @vkniazeu , This issue appeared in a Typescript upgrade, not angular2-logger upgrade. See #39. If you use the latest officially released version of Typescript 1.8.10 you won't see it. It should be fixed in 0.4.2 even for newer versions of Typescript though, if you are following the Quickstart guide. Somehow you are pointing to the Is there a step you are doing different from the Quickstart guide? |
Hi @langley-agm,
I am not referencing or pointing to
Thank you for your help and insight! |
Thanks for the kind words @vkniazeu. Sadly I haven't been able to dig into webpack, there's just no way to sanely keep up with so many different frameworks poping up by the day and Angular Team not making up their minds about them doesn't make it any easier. The root cause of this issue is the fact that Typescript is trying to compile a third party library in the first place. I don't think there's any other language that does that. The library is compiled in 1.8.10 and people should be able to use it in newer versions if they want to without finding these kind of conflicts. You already have the compiled files in the distribution, source files are merely for reference. That's why I don't want to just apply a change like the one you suggested because it will be hiding the real problem. The Quickstart is based off the Angular 2's Quickstart which uses SystemJS so I applied a fix for it. I'm thinking this is an issue on Webpack configuration but I haven't used it yet so I can't confirm it, if someone finds something missing in this repo that webpack needs in order to use the compiled files and not the source files I'll hapily look into it. How are you telling webpack where to find 'angular2-logger/core' ? Is there a way to tell him to use either the One more thing I can think of that might be affecting / could help with this is the |
@langley-agm, I am fairly new to Typescript and brand new to webpack, but my understanding is that it goes through all .ts files referenced in your main.ts file and its children and uses the import statements to to bundle up any and all references withing your code.
Many other packages like On a separate note, aside from all the configuration and typings, wouldn't any strong type language compiler complain about the fact that your function is marked as returning a number (Level) while it actually returns a string in this line without any proper casting or a similar conversion?
|
@types is a corporate name in NPM which holds different projects: https://www.npmjs.com/~types, you don't put your definitions there, you create a project there with the definitions, however this is useful for libraries that are not typescript. If you notice lodash, protractor are js libraries not Typescript libraries, that's why you need the typings from a TS library which has no code but the definitions (
Angular Team seems to be doing this, I don't know if just because it makes things easier for them or what, but they used to include them, RxJS does include them ( https://github.com/ReactiveX/rxjs ) and I definitely see a use case on including them, its been an innumerable number of times in which I've had to read Angular 2 source code and I see no reason why I should go to the Github and search for the code manualy when you can just have it there in your project and your IDE point you to them. Whether you download the source code or not should be a user's desicion imho, that's how other package managers work.
Well this is a decision on the language's creator/s. In Typescript 1.8.10 this isn't necessary, in newer versions it is. If I move my project to a newer version of Typescript I'll make sure to update that file. However, the typescript version in which this library is compiled, should not affect the project in which you use it, cause it is already compiled into JS. Again, whether this is correct or not, doesn't matter, the root cause of this issue is the fact that your project is trying to compile Third Party |
What happens if you try this? :
|
The latter suggestion didn't help, but it's okay. |
enough? yes, I'm not trying to go for what's the minimal enough though, if its useful for some users to have the source files there i'll leave them there. Like I mentioned other package managers have a flag to decide whether to include the source files in the downloaded packaged library or not, this is a lacking functionality in npm, however this is nowhere near the scope of this issue. |
@vkniazeu If you are able to share your repo I can take a look at it, otherwise you could probably reproduce it in a small project that I do have access to. Not sure how hard it would be to do it in something like plunkr, probably its just easier to create a demo project in github because of all the dependencies and setup required in angular 2. |
@langley-agm, here's a minimal CLI webpack setup to reproduce the error.
Download: test-cli.zip |
Reproducible with "angular2-logger": "0.4.5". |
Yea, no real changes in these minor releases yet, I was just trying to fix some stuff rendering wrong from the .md file. It looks fine now in GitHub but npm still doing weird stuff with it. |
The test setup posted by @vkniazeu will actually install the outdated SystemJS version of the cli. A better setup is the following:
Also note the Edit: Oops, disregard the next two paragraphs. Obviously we want to use the ES6 dist for CLI production builds because tree-shaking algorithms (removing unused code paths) work best with ES6 modules.
Solution (Hack)
ConclusionThe angular CLI won't automatically pick up the es6 dist & core.d.ts, it needs both to be in the same directory and be pointed directly at it. If you have a look through |
@langley-agm Just so you know, I don't believe this or #39 are related to type-bundling at all. According to the docs,
In other words, |
No one said otherwise =)
This is why there's no core.ts file in the distribution now.
This is not what we're aiming for.
I noticed. However no one knows how Angular libraries are supposed to be structured yet, like you just mentioned even the Angular team keeps changing this structure. As reference you can see other typescript libraries like RxJS do include the .ts files, It is useful to have those in the distribution. |
Heya, @langley-agm!
Ah, I see your rational. I don't know about other build processes, but the angular-cli still has a habit of finding the .ts versions and using them. Not entirely sure why it does this, I guess they internally set the allowjs flag or something. Look at the file path that's giving me the error: I'm currently using [email protected] and the master branch of the angular-cli.
Ok, I skimmed through #39 and thought that's what you were saying at the end. It's a pretty long thread. At the end, you talked about separating the .d.ts files from .ts files as a potential solution. I don't think that will make any difference though, because it looks like the CLI is set up to compile a .ts whenever it's in the same folder as a .js. You can see the difference by doing that little copy-paste hack with the ugly import statement I posted. Since the dist/es6 folder doesn't have any competing .ts files, it just uses the .js and doesn't try to compile anything. I have a better solution now that involves some refactoring. I'll push it into a fork a bit later so you can tell me what you think. |
It made a difference, and it closed the defect, that defect wasn't about angular-cli, if you follow the regular quickstart guide you won't see this issue. In this case angular-cli is making typescript use the .ts files instead of the .dts, why? that I don't know yet. I took a look at it but the documentation seems to be outdated, its obviously in constant change because angular 2 is in constant change. Once they get to a more stable position and update their documentation I'll take a look again to see if I can help finding out the right configuration when using angular cli to avoid this issue. Once again, you should not be compiling third party code. It's already compiled for you. Note: |
Because it's compiling. It's looking for .ts files. The types resolve while you're writing code, but break at build-time. The only thing strange is that angular-cli is using ts files when the index was a js, and I think that's a bug.
I'm not confused. To clarify your confusion, bundling declarations completely irrelevant. Just have your project compile with --declaration into a spot module resolution will find it. If you don't want to, just set
I see, your solution hacked node resolution by removing the file it's designed to check first. This is a strange problem to have in the first place. Excuse my confusion.
TypeScript is fine. Hopefully I can help, here's a working solution: I put some detail how it works: Then got sleepy. Probably forgot a thing or two explanations, open for questions/feedback. |
I didn't hack a solution. I applied a real solution one contributor recommended in order to give the user the ability to use this library typings without having Typescript forcefully compile a third party library that was already compiled in the first place.
No, is not, they recognized it themselves and they are working on this: microsoft/TypeScript#4433
The fact that you are discussing two different issues as the same one makes me thing you are indeed confused. Previously, the were many dts files along each corresponding ts file. When the library user imported a file, typescript would load the ts instead of the dts, and by doing so, compiling it. This had absolutely nothing to do with angular-cli. This was an issue for one simple reason: Because of how typescript is built, it would force them to compile this third party library, which is not desired. In order to avoid this, the core.ts / core.d.ts file that was previously importing itself files like "logger", now doesn't import anything but instead includes the whole definition of the entire core module. Since core.d.ts has no code but is only a bundle of definitions now, core.ts was not needed anymore and removed, this is not a hack, this is by design. That's another defect and it's tested and closed already.
Angular-cli doesn't compile, it configures your project so typescript compiles it. Once again, if you follow the Quickstart guide you won't have this issue. And the quickstart guide compiles the code too, except it doesn't compile this third party library code, it only uses its typings to make sure you are using it correctly. You should be able to compile your code without having to compile third party libraries, that's nonsense, if your project uses 400 libraries and you already have the compiled distribution of those 400 libraries why would you want to recompile them all everytime you make any change to your code? you should be able to only compile your code just as you are able to do so with any other compiled language. The issue here is to find out what's angular-cli configuring/doing different than the Quickstart Guide that makes typescript look for the .ts files instead of using the .d.ts. Again, the quick start also makes typescript compile the code and it does not have this issue, angular-cli is doing something different, I'm not saying its an angular-cli issue, I'm saying we need to find out what's doing different in order to find the root cause of this issue that's only happening now when using angular-cli. |
Ooooooooooooooooooooooooooooooooooooooooooooooooooooh right! I remember reading this now: So a js imports a ts in TypeScript 2.0.2 |
Recall the order it checks things during module resolution. Yup, the ts files take priority.
Don't worry, you can import libs without compiling them! I can show you how, if you'd like. Basically your .d.ts files and .js files (compiled artifacts) should be in the same folder as each other. Keep your ts files somewhere else so they don't interfere. That's what I did here: https://github.com/TheFirstDeity/angular2-logger/ |
I do recall it, the user points to angular2-logger/core when importing, core.d.ts is used since there's no core.ts file.
We already do this ! Please follow the Quickstart guide, not the angular-cli one, to see what were talking about. |
"We" who? The person who opened this issue is using angular-cli@webpack. That's great you got it to work with the Quickstart, but the not what this issue is about. I came to try and help resolve this issue, and your hyper-defensive responses aren't helping anyone. Please, let's get back to the technical stuff and leave our egos at the door. Since angular-cli@webpack builds using typescript 2, I think it makes sense that he would be getting that error. What do you think? |
The person who actually helped fixing the root cause of the previous issue and me.
I'm not being defensive I'm trying to make you see what the issue is, you are talking indistinctly between angular-cli and typescript compiling, its two completely different things, we need to understand that so we can fix this issue.
I know that. That's why this issue is still open, and the one you keep talking about and saying its unrelated to bundling is already closed. You are the one discussing two different things and getting confused because of it. You are saying bundling doesn't have to do anything with 39, not with this one. I'm explaining why bundling was mentioned in 39 not in this one. What I'm trying to make you see is that this exception has been previously fixed as far a Typescript compiling is referred to; By giving a bundle definitions file we give typescript all he needs in order to avoid having to compile this library. And the proof of that, is that the quickstart guide is using typescript just fine without throwing this exception (even if you use a newer version of typescript in your project). Absolutely nothing to do with ego =) This issue is something related to typescript doing something different when configuring it manually and when using it through angular-cli. We need to know what's doing different when using angular-cli first. Is it using its own typescript configuration? Is it's build script moving things around? Why is it that this error appears when using angular-cli and not in the regular quickstart? Let's find the root cause before we attempt to fix it, otherwise we're risking to merely patch it and hide the root cause just like we did on 39. If you agree please ping me in gitter and lets schedule some time when we can get together and discuss it, I'm totally up for that. |
Here's a keypoint. Like I've mentioned so many times before, you should not compile third party libraries, it has a distribution already compiled, so it doesn't matter what version of typescript webpack is using, it should not throw this error if it should not compile it in the first place. You need to be able to use a third party library written in a previous version than the one you are using because in the end whats actually going to be used is Javascript. If you are using 400 typescript libraries and suddenly there's a breaking change in a new typescript version and you update your code to use that new version you should not have to wait for those 400 libraries to update their codebase to the newer version as well in order for you to use that new version. Does this makes sense? |
|
Hey @langley-agm, I hope you're well. I agree that lib files shouldn't be compiled, but they will be anyways. There are several reasons why:
The angular-cli probably runs the TypeScript compiler with I think it's fine. I think npm packages should separate their js from the ts. I think having your source & output mixed together is worse, not to mention it's just messy. I think the way to go is to mimic how ng2 organizes their packages, since this is an ng2 library. Deploy as es6 with a umd-es5 bundle, and use the You have no idea ahead of time what code-paths the client will call, for example, so you can't deliver a 'final' tree-shaken library. It'll still be processed by the client's toolchain and transformed however they need it. It's depressing. But if it makes you feel better... You're right to think this is ridiculous. My favorite episode of "Adventures in Angular" describes client-side web development as a toxic sewer of monkey-patches that you need Adderall to navigate. Every project is a dumpster fire, and every file might be processed additional times before it's deployed. Your lib is fair-game for tsc and other tools. After all, nothing's actually compiled until it hits the browser. Just remember... I'm not an idiot. I spent a lot of time thinking about this. I was hoping you'd actually look at how I solved the problem and give me some feedback, then I'd issue a pull request if you're happy with the design direction. At the very least, I was hoping this project would benefit by looking at some of the ways I solved problems. Either way, I'll continue to use my little fork of this project and maybe add to it. This project is interesting. 👍 |
Ha, edited the best part :) |
It's a good edit, though. I want to move in a positive direction. :) |
A lot of the refactoring I did in my forked version was just to preserve the idea of novelty sub-packages like It'll require everyone to import from the root I learned a lot by experimenting with this. 😄 |
Just to clarify from earlier, running In the blog post, he talks about how it's necessary to use es6 js when you run I'm not sure if that part was clear when I explained earlier. |
I just went through Angular2's webpack setup guide and this error does not happen even though I'm using Now that I've seen that it's nothing to do with the structure or webpack, I'm going to fix this specific error so it doesn't hurt those using angular-cli, however I strongly suggest to take a closer look at it or even open an issue in their repo so they can narrow the root cause and once we find it, if there's something we have to do on our side we'll take a look at it, because compiling third party libraries already compiled will make your build process inefficient to say the least. This is the guide I followed: https://angular.io/docs/ts/latest/guide/webpack.html And I had to do no extra configuration for the angular2-logger to work. |
Thank you, @langley-agm. |
Hello, I seem to be having this same issue using Example error message:
|
@ascreamingweas Yes, this entire thread is about this problem :)
|
Yea @ascreamingweas , In short, it means your build process is compiling this third party library which is an overhead in your build process since the library is already compiled, the fact that you get this error means your build process can be highly improved in order to avoid already compiled third parties (not only this one, but any), getting compiled once again by your PC. If you follow the Quickstart Guide in Angular 2 for either SystemJS or Webpack you won't get this error. If you don't care about this extra overhead in your project's build process you can leave it as is, I'll be commiting a fix for this error soon enough. |
Thank you @vkniazeu @langley-agm for your help with this!! |
Hi all, I've looked at the fix but I cant seem to get it to apply to my statement... Does anyone know what I need to do? |
Hi @bloobird , Your statement is not related to this fix, what are you trying to do and what are you expecting in the user var? |
This problem appeared with angular2-logger 0.3.0 after I updated to Angular 2 rc5.
I just updated angular2-logger to its latest 0.4.2 and the problem still shows up.
ERROR in [default] \node_modules\angular2-logger\app\core\logger.ts:62:38 Type 'string' is not assignable to type 'Level'.
Changing the line from:
private _loadLevel = (): Level => localStorage.getItem( this._storeAs );
to
private _loadLevel = (): any=> localStorage.getItem( this._storeAs );
seems to resolve the problem.
The text was updated successfully, but these errors were encountered: