Skip to content

No errors on array initialization if any element is of any typeΒ #46190

Closed
@chrisirhc

Description

@chrisirhc

Bug Report

πŸ”Ž Search Terms

  • any type used in array initialization

πŸ•— Version & Regression Information

3.9.7 and beyond

⏯ Playground Link

https://www.typescriptlang.org/play?ts=3.9.7#code/MYewdgzgLgBBIFsCmYCuCBGSBOAuGamOMAvDAIwDcAUKJLPMlABYCWYA5kgDYRL4BDMAE9SFGnWgxg+aNnYcA2gF0xixinRZsAGjiIkLBTz7LKQA

πŸ’» Code

const somenumber: number = 1;
const somethingelse: any = 1;
const c: string[] = [somenumber, somethingelse];

πŸ™ Actual behavior

No errors reported.

πŸ™‚ Expected behavior

Error reported on the array initialization, on line 3, on the use of somenumber in a string array .

Side note

If this is expected behavior when any item is any, is there a way to have the typescript lint report this?
It seems odd that the initialization line reports no error or warning at all, since there's a specific type declared on that line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions