Reports calling global objects like Math, JSON, or Reflect as functions.
✅ This rule is included in the ts untyped presets.
The global objects Math, JSON, Reflect, and Atomics are not constructors or functions.
They are built-in objects that provide utility methods and properties as namespaces.
Attempting to call them as functions or instantiate them with new will result in a TypeError at runtime.
Error ts(2349) ― This expression is not callable.
Type 'Math' has no call signatures.
const
const data:any
data = JSON();
Error ts(2349) ― This expression is not callable.
Type 'JSON' has no call signatures.
const
const reflected:any
reflected = Reflect();
Error ts(2349) ― This expression is not callable.
Type 'typeof Reflect' has no call signatures.
const
const instance:any
instance = newAtomics();
Error ts(2351) ― This expression is not constructable.
Type 'Atomics' has no construct signatures.
const
const value:number
value =
var Math:Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.
Math.abs(x: number): number
Returns the absolute value of a number (the value without regard to whether it is positive or negative).
For example, the absolute value of -5 is the same as the absolute value of 5.
@param ― x A numeric expression for which the absolute value is needed.
abs(-5);
const
const parsed:any
parsed =
var JSON:JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.
JSON.parse(text: string, reviver?:(this:any, key:string, value:any)=> any): any
Converts a JavaScript Object Notation (JSON) string into an object.
@param ― text A valid JSON string.
@param ― reviver A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.
@throws ― {SyntaxError} If text is not valid JSON.
Returns the string and symbol keys of the own properties of an object. The own properties of an object
are those that are defined directly on that object, and are not inherited from the object's prototype.
@param ― target Object that contains the own properties.
Adds a value to the value at the given position in the array, returning the original value.
Until this atomic operation completes, any other read or write operation against the array
will block.
If your codebase redefines these objects and is guaranteed to run in an environment that allows that, you might not want to enable this rule.
For example, if you target a legacy runtime with legacy non-standard JavaScript semantics, modern standard practices may not apply to you.