Any Type

Verze:

31. 12. 2025

Zodpovědná osoba:

Dominik Šlechta

The any type MUST NOT be used. The unknown type MUST be used when the type is truly unknown, with type guards to narrow it.

The any type MUST NOT be used.

The unknown type MUST be used when the type is truly unknown.

Type guards MUST be used to narrow unknown types.

Example (Correct):

function parseJson(json: string): unknown {
    return JSON.parse(json)
}

function isProduct(item: unknown): item is Product {
    return (
        typeof item === 'object' &&
        item !== null &&
        'id' in item &&
        'name' in item
    )
}

Example (Incorrect):

function parseJson(json: string): any {
    return JSON.parse(json)
}