Some types have several ways to be defined, and some others could be dangerous. This rule suggests a consistent use of types.
Non-Compliant Code Examples
// use lower-case primitives for consistency
conststr: String='foo';constbool:Boolean=true;constnum: Number=1;constsymb: Symbol=Symbol('foo');constbigInt: BigInt=1n;// use a proper function type
constfunc: Function=()=>1;// use safer object types
constlowerObj: Object={};constcapitalObj: Object={a:'string'};constcurly1:{}=1;constcurly2:{}={a:'string'};
Compliant Code Examples
// use lower-case primitives for consistency
conststr: string='foo';constbool:boolean=true;constnum: number=1;constsymb: symbol=Symbol('foo');constbigInt: bigint=1n;// use a proper function type
constfunc:()=>number=()=>1;// use safer object types
constlowerObj: object={};constcapitalObj:{a: string}={a:'string'};constcurly1: number=1;constcurly2: Record<'a',string>={a:'string'};
シームレスな統合。 Datadog Code Security をお試しください
Datadog Code Security
このルールを試し、Datadog Code Security でコードを解析する
このルールの使用方法
1
2
rulesets:- typescript-best-practices # Rules to enforce TypeScript best practices.