이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: typescript-best-practices/no-var-requires

Language: TypeScript

Severity: Warning

Category: Best Practices

Description

Use ESM instead of CommonJS imports.

Non-Compliant Code Examples

var foo = require('foo');
const foo = require('foo');
let foo = require('foo');
let foo = trick(require('foo'));
var foo = require?.('foo');
const foo = require?.('foo');
let foo = require?.('foo');
let foo = trick(require?.('foo'));
let foo = trick?.(require('foo'));
const foo = require('./foo.json') as Foo;
const foo: Foo = require('./foo.json').default;

// const foo = <Foo>require('./foo.json');

// https://github.com/typescript-eslint/typescript-eslint/issues/3883
// const configValidator = new Validator(require('./a.json'));
// configValidator.addSchema(require('./a.json'));

Compliant Code Examples

import foo = require('foo');
require('foo');
require?.('foo');
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis