angular2-logger: Type 'string' is not assignable to type 'Level'
I get this error for at least the version 0.2.3. I can’t yet update to 0.3.0.
Line: /angular2-logger/app/core/logger.ts:59:38
Related to this? https://basarat.gitbooks.io/typescript/content/docs/tips/stringEnums.html
changing the line 59 from:
private _loadLevel = (): Level => localStorage.getItem( this._storeAs );
to
private _loadLevel = (): Level => +localStorage.getItem( this._storeAs );
Seems to fix it (converts string to number)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 38 (26 by maintainers)
Commits related to this issue
- Created a global definition file, fixes #39. — committed to code-chunks/angular2-logger by langley-agm 8 years ago
- Missing change from previous commit that fixes #39. — committed to code-chunks/angular2-logger by langley-agm 8 years ago
Only to recall: this problem is not caused because of this “one character”, it’s caused because TypeScript compiler compiles the
.tsfiles instead of using the.d.tsfiles when resolvingimport "angular2-logger";. For me, as a user of the library, if i addimport "angular2-logger";to one of my source files I don’t care a pap for it that angular2-logger is build by TypeScript compiler (1.8, 1.7. or even 1.0), or Babel or whatever you want (CoffeeScript, Closure, Kotlin, …). If I addimport "angular2-logger";to one of my source files I expect some*.jsfiles somewhere on my disk and ideally one*.d.tsnearby the*.jsfiles. Nothing more (ok, apackage.jsonwith a correctmainandtypingsattribute, too).Therefore, other libraries separate the source files (
*.ts) from the generated files (*.d.ts,*.js) in the distribution. But this library does not …Overall, it’s good style to separate source files from generated files, and as a side effect it would solve this problem.
@k7sleeper sorry, miss-clicked the close button.
The typescript compiler doesn’t use
.d.tsfiles, it generates them. If you wanted to compile.d.tsfiles you’d have to write them yourself, or compile once to generate the.d.tsfiles and a second config that compiles those into js. However,.d.tsfiles are merely the definitions of the API, you’d be compiling empty definitions with no implementation whatsoever, you’d be able to call the functions but they wouldn’t be doing anything.Also
package.jsondoesn’t tell the compiler how to compile, that’stsconfig.json.Just clarifying some things to avoid miss-conceptions. I’ll be carefully reviewing your pull requests with more calm as soon as I get a chance.
Thanks for contributing !
@vcorr I was able to reproduce your issue when I use
typescript 1.9.0-dev.20160503, however that’s not an official release yet.I ran some tests and this issue is not happening with the latest official release:
1.8.10. I suggest you to use that instead.However, I will leave this issue open in case it continues to occur after they officially release the next version, thank you !