0

I have to check

if (!window.MSStream) ...

but I get error in TypeScript, intellisense underlines MSStream object, because it is not declared - and that's exactly my point to check - but I can't build app in Angular2 because of that error. How can I "cheat" typescript or force him not to be so strict and act like regular javascript and just do that check and leave me alone...

2 Answers 2

3

MSStream is not part of the type definitions provided for window. You can either add this type on your own or you access this property via square brackets. Then the typescript compiler should be fine.

if (!window['MSStream']) { /* do something */ }
Sign up to request clarification or add additional context in comments.

2 Comments

You're right, it worked! Although I was SURE I tried that before... obviously I didn't :)
I know what you mean. :-) Sometimes I run into the same issues. ;-) Happy Coding!
1
if (!window['MSStream']) { /* do something */ }

doesn't work anymore. I get

Element implicitly has an 'any' type because index expression is not of type 'number'.

But this works:

(window as Window & {MSStream?: { /* props go here */}}).propXYZ

2 Comments

Wow! This really looks opposite of elegant. Well, thanks for the info
@Dalibor well the beauty is in the eye of the beholder :) Type-safety comes at a cost here. But it DOES make your intentions more explicit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.