S
S
sanex33392015-08-12 23:01:36
JavaScript
sanex3339, 2015-08-12 23:01:36

Typescript: how to properly type an object and how to properly validate window.jQuery?

Today I started looking at typescript, 2 questions appeared:
1)
There is a code

class Static {
  static object: Object = {
    abc: <string>'abc',
    number: <number>123	
  };
}

console.log(Static.object.abc);

If you do this, then there will be an error 'property `abc` does not exist on type `object`, if you change Object to any - everything will be fine, explain why?
2) I connected jquery normally, but in my code there is a check for the presence of window.jQuery, if it is missing - appendim in the html script tag with jquery, the compiler itself swears '`jQuery` does not exist on type `window`'. How to fix it?
Thanks for answers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2015-08-12
@sanex3339

As for the second question, it looks like this is how it should be:

interface JQueryWindow extends Window {
    jQuery;
}

if (!(<JQueryWindow>window).jQuery) {
  console.log(1);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question