# Source: https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/typescript-code-style/no-inferrable-types.md

---
title: Avoid explicit type declarations for variables and params
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid explicit type declarations for variables and params
---

# Avoid explicit type declarations for variables and params

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `typescript-code-style/no-inferrable-types`

**Language:** TypeScript

**Severity:** Notice

**Category:** Best Practices

## Description{% #description %}

When you set an initial primitive value to a TypeScript parameter, property, or variable their respective type can be inferred. Explicitly adding type annotations in some cases can make your code more verbose and prevent TypeScript from inferring a more specific literal type.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```typescript
const a: bigint = 10n;
const a: bigint = -10n;
const a: bigint = BigInt(10);
const a: bigint = -BigInt(10);
const a: bigint = BigInt?.(10);
const a: bigint = -BigInt?.(10);
const a: boolean = false;
const a: boolean = true;
const a: boolean = Boolean(null);
const a: boolean = Boolean?.(null);
const a: boolean = !0;
const a: number = 10;
const a: number = +10;
const a: number = -10;
const a: number = Number("1");
const a: number = +Number("1");
const a: number = -Number("1");
const a: number = Number?.("1");
const a: number = +Number?.("1");
const a: number = -Number?.("1");
const a: number = Infinity;
const a: number = +Infinity;
const a: number = -Infinity;
const a: number = NaN;
const a: number = +NaN;
const a: number = -NaN;
const a: null = null;
const a: RegExp = /a/;
const a: RegExp = RegExp("a");
const a: RegExp = RegExp?.("a");
const a: RegExp = new RegExp("a");
const a: string = "str";
const a: string = 'str';
const a: string = `str`;
const a: string = String(1);
const a: string = String?.(1);
const a: symbol = Symbol("a");
const a: symbol = Symbol?.("a");
const a: undefined = undefined;
const a: undefined = void someValue;
```

## Compliant Code Examples{% #compliant-code-examples %}

```typescript
const a = 10n;
const a = -10n;
const a = BigInt(10);
const a = -BigInt(10);
const a = BigInt?.(10);
const a = -BigInt?.(10);
const a = false;
const a = true;
const a = Boolean(null);
const a = Boolean?.(null);
const a = !0;
const a = 10;
const a = +10;
const a = -10;
const a = Number("1");
const a = +Number("1");
const a = -Number("1");
const a = Number?.("1");
const a = +Number?.("1");
const a = -Number?.("1");
const a = Infinity;
const a = +Infinity;
const a = -Infinity;
const a = NaN;
const a = +NaN;
const a = -NaN;
const a = null;
const a = /a/;
const a = RegExp("a");
const a = RegExp?.("a");
const a = new RegExp("a");
const a = "str";
const a = 'str';
const a = `str`;
const a = String(1);
const a = String?.(1);
const a = Symbol("a");
const a = Symbol?.("a");
const a = undefined;
const a = void someValue;
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}