question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type 'string' is not assignable to type 'Level'

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:38 (26 by maintainers)

github_iconTop GitHub Comments

2reactions
k7sleepercommented, Aug 15, 2016

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.

2reactions
langley-agmcommented, Jun 2, 2016

@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 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Type 'string' is not assignable to type - Stack Overflow
Yes, "Banana" is the type. It is extends String so it's assignable to String . Additionally, a type extends a Union Type when...
Read more >
Type 'string' is not assignable to type in TypeScript | bobbyhadz
The "Type 'string' is not assignable to type" TypeScript error occurs when we try to assign a value of type string to something...
Read more >
Type 'string' is not assignable to type 'string[]' : r/typescript
Hi - I'm trying to create a component where one of the properties of the component is an array of strings. I've set...
Read more >
Type 'string' is not assignable to type 'ReadPreference'.
Task - A task that needs to be done. NODE-4187 Investigate NODE-4186 - Type 'string' is not assignable to type 'ReadPreference'. Unknown - ......
Read more >
Documentation - Everyday Types - TypeScript
No type annotation needed -- 'myName' inferred as type 'string' ... 'string'.2345Argument of type 'number' is not assignable to parameter of type 'string'....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found