Skip to content

Union with any produces unexpected result #16958

Closed
@yeerkkiller1

Description

@yeerkkiller1

TypeScript Version: 2.4.0

Code

declare function test(num: string): void;

let withString: number | string;
// Error: `Type 'number' is not assignable to type 'string'.`, as expected. withString might be a number, which does not have the necessary properties to act as a string.
test(withString);

let withAny: number | any;
// No error
test(withAny);

Expected behavior:
I expected the second case to give an error. withAny might only have the properties of a number.

Actual behavior:
withAny reduces to the type any, and so does not give an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions