Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Bug(KnockoutSpa): Router TS issue #267

Closed
wants to merge 2 commits into from
Closed

Bug(KnockoutSpa): Router TS issue #267

wants to merge 2 commits into from

Conversation

MarkPieszak
Copy link
Contributor

TS erroring out (unable to build) due to crossroads.normalizeFn = crossroads.NORM_AS_OBJECT; <-- left hand assignment

ERROR in ./ClientApp/router.ts
(21,9): error TS2450: Left-hand side of assignment expression cannot be a constant 
or a read-only property.

TS erroring out (unable to build) due to `crossroads.normalizeFn = crossroads.NORM_AS_OBJECT;` <-- left hand assignment

```
ERROR in ./ClientApp/router.ts
(21,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property.
```
@SteveSandersonMS
Copy link
Member

Thanks for reporting this.

I'm not following why TypeScript 2 is reporting that error. Is it a bug in TypeScript 2? Why does it think the LHS of the assignment is a constant?

If we do need to work around it, could we do so in a more targeted way that doesn't discard all type information for the crossroads package?

@MarkPieszak
Copy link
Contributor Author

It looks like changing this to import crossroads = require('crossroads'); is the best bet, I meant to change it to that, apologies! That way we keep the intellisense.

Let me look into this more and see why it's creeping up now in the first place, I'll get back to you!

@SteveSandersonMS
Copy link
Member

@SteveSandersonMS
Copy link
Member

Merged

@MarkPieszak
Copy link
Contributor Author

MarkPieszak commented Aug 19, 2016

Since you were wondering as well, found out why this was creeping up now with 2.0. Apparently it was a TS bug because it wasn't showing up. This was fixed in 2.0. (Apparently another workaround is that we could do (crossroads as any).normalizeFn ? Interesting.)

http://stackoverflow.com/questions/38818475/left-hand-side-of-assignment-expression-cannot-be-a-constant-or-a-read-only-prop

This is because in es6 all module's variables are considered constants.

microsoft/TypeScript#6751 (comment)
In TypeScript 2.0 the bug (of not reporting this error) was fixed.

Since mongoose is still using the commonjs - var mongoose = require("mongoose") - not the es6 import syntax (which is used in the typings), you can suppress the error by assuming the module is of type any.

WORKAROUND:

(mongoose as any).Promise = global.Promise;

@MarkPieszak MarkPieszak deleted the patch-1 branch August 19, 2016 13:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants