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

Most upvoted comments

Only to recall: this problem is not caused because of this “one character”, it’s caused because TypeScript compiler compiles the .ts files instead of using the .d.ts files when resolving import "angular2-logger";. For me, as a user of the library, if i add import "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 add import "angular2-logger"; to one of my source files I expect some *.js files somewhere on my disk and ideally one *.d.ts nearby the *.js files. Nothing more (ok, a package.json with a correct main and typings attribute, 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.

let’s the TypeScript compiler use core.d.ts

The typescript compiler doesn’t use .d.ts files, it generates them. If you wanted to compile .d.ts files you’d have to write them yourself, or compile once to generate the .d.ts files and a second config that compiles those into js. However, .d.ts files 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.json doesn’t tell the compiler how to compile, that’s tsconfig.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 !