Type 'string' is not assignable to type 'Level'
See original GitHub issueIssue Description
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:
- Created 7 years ago
- Comments:38 (26 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 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*.js
files somewhere on my disk and ideally one*.d.ts
nearby the*.js
files. Nothing more (ok, apackage.json
with a correctmain
andtypings
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.
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’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 !