3

I have a method:

deepCopy (destination: any, source: any {...}

and I would like to check if the source is of any primitive type in ExtJS it would look like Ext.isPrimitive(source) but I can't find a way to do it in TypeScript.

Yoda
  • 17,363
  • 67
  • 204
  • 344
  • 1
    Same as a js solution – Nitzan Tomer May 22 '17 at 07:36
  • @NitzanTomer Primitive is not a type(?) i can't to `source instanceof primitive` or `typeof source == 'primitive'`. – Yoda May 22 '17 at 07:45
  • In js (and then in ts as well), a value can be either a primitive or an object. You can take one of the ways described in the answers to the duplicated question and just negate it to get a `isPrimitive` function. – Nitzan Tomer May 22 '17 at 07:51
  • Do you mean check at compile time or run time? If the former, why not just declare the function as `deepCopy(destination: any, source: object)` and let TypeScript do the checking? –  May 22 '17 at 08:36
  • @Aernor `obj && typeof yourVariable !== 'object'` should be good as a `isPrimitive` function. I don't understand what the definition of the typescript `object` type has to do with this – Nitzan Tomer Jul 09 '18 at 14:04

0 Answers0