src/content/docs/linter/rules/use-consistent-builtin-instantiation.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.7.2` - Diagnostic Category: [`lint/style/useConsistentBuiltinInstantiation`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`no-new-wrappers`](https://eslint.org/docs/latest/rules/no-new-wrappers){
"linter": {
"rules": {
"style": {
"useConsistentBuiltinInstantiation": "error"
}
}
}
}
Enforce the use of new for all builtins, except String, Number and Boolean.
new Builtin() and Builtin() work the same, but new should be preferred for consistency with other constructors.
Enforces the use of new for following builtins:
Disallows the use of new for following builtins:
These should not use
newas that would create object wrappers for the primitive values, which is not what you want. However, withoutnewthey can be useful for coercing a value to that type.
Note that, builtins that require new to be instantiated and
builtins that require no new to be instantiated (Symbol and BigInt) are covered by the
noInvalidBuiltinInstantiation rule.
const text = new String(10);
const now = Date();
const text = String(10);
const now = new Date();