isA<T extends JSAny?> method

  1. @Since('3.4')
bool isA<T extends JSAny?>()

Whether this JSAny? is the actual JS type that is declared by T.

This method uses a combination of null, typeof, and instanceof checks in order to do this check. Use this instead of is checks.

If T is a primitive JS type e.g. JSString, this uses a typeof check that corresponds to that primitive type e.g. typeofEquals('string').

If T is a non-primitive JS type e.g. JSArray or an interop extension type on one, this uses an instanceof check using the name or @JS rename of the given type e.g. instanceOfString('Array'). Note that if you rename the library using the @JS annotation, this uses the rename in the instanceof check e.g. instanceOfString('library1.JSClass').

In order to determine the right value for the instanceof check, this uses the name or the rename of the extension type. So, if you had an interop extension type JSClass that wraps JSArray, this does an instanceOfString('JSClass') check and not an instanceOfString('Array') check.

There are two exceptions to this rule. The first exception is JSTypedArray. As TypedArray does not exist as a property in JS, this does some prototype checking to make isA<JSTypedArray> do the right thing. The other exception is JSAny. If you do a isA<JSAny> check, it will only do a null-check.

Using this method with a T that has an object literal constructor will result in an error as you likely want to use JSObject instead.

Using this method with a T that wraps a primitive JS type will result in an error telling you to use the primitive JS type instead.

Implementation

@Since('3.4')
external bool isA<T extends JSAny?>();