'Why is it possible to pass a value of type 'any' to a typed parameter without an error?

The TypeScript transpiler does not emit an error for the following code:

function test1(test: any) {
    test2(test);
}

function test2(test: string) {

}

I expected an error to be emitted for this code because if an object of type 'any' can be passed to a parameter of type 'string' without any error, then the code could cause a non-string could be passed to test2 at runtime. It should be trivial for the transpiler to know there is a potential type safety violation here?

I thought the point of TypeScript was to ensure type safety at compile time? What am I missing here? Is there an option I need to enable in tsconfig.json or something?

Edit:

I don't think my generic example that I included above is getting my point across. Here is a snippet from my actual application. The code is part of a Google Apps Script application, and I am using the @google/clasp typings.

// 'sheet' is of type GoogleAppsScript.Spreadsheet.Sheet
// The return value of this function is any[][]
// There is nothing I can do to change this, it is an import from a library
const cells = sheet.getSheetValues(2, 1, -1, -1);

for (const cell of cells) {
    const registration = cell[0]; // any
    const profileName = cell[1]; // any
    const uuid = cell[2]; // any

    //
    // The signature of this constructor is as follows:
    // constructor(aircraft: InputAircraft, profileName: string, uuid: string)
    //
    // Passing 'any' to the parameters of this constructor does not cause any 
    // warning or error, even with strict=true in my tsconfig.conf or even 
    // with eslint set up with the @typescript-eslint/no-explicit-any rule 
    // turned on.
    //

    yield new InputProfile(registration, profileName, uuid);
}


Solution 1:[1]

any is intentionally left in as a way around the type checker, for working with legacy untyped Javascript code. It should only be used in situations where you have code which is not typed or which cannot be easily typed.

With --strict (which includes noImplicitAny, among other things), you'll get a warning if a variable is ever accidentally of type any. If you write any, the compiler assumes you meant it and know what you're doing. If you really want to go without the ability to use any at all, then no-explicit-any is an ESLint setting you can turn on.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Silvio Mayolo