Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:typescript-best-practices/ban-types
Language: TypeScript
Severity: Notice
Category: Best Practices
Description
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'};
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- typescript-best-practices # Rules to enforce TypeScript best practices.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines