Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noImplicitAny infers any for typed parameter of union's common function #58133

Closed
adamhamlin opened this issue Apr 9, 2024 · 2 comments
Closed

Comments

@adamhamlin
Copy link

πŸ”Ž Search Terms

noImplicitAny any union

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about: noImplicitAny

⏯ Playground Link

https://www.typescriptlang.org/play?noImplicitAny=false&ts=4.9.5#code/JYOwLgpgTgZghgYwgAgLIE8Aq6AOKDeAUMicsACYD8AXMiAK4C2ARtANzGkhyMS0DOYKKADmHAL6FCMeiARhgAexDJG6AGKyEACgA2wQQHkoqODloZseANoBdZAB80ZgDyDhIEQBo0WXBAA+AEpaADdFCmQiUmR9IxMzADoYRSgAUUQAC21tRWYAKyDkAF4AqM4YknIIXQhIZDz8xIoOGPEgiUIgA

πŸ’» Code

interface MyType {
    id?: number;
    name: string;
}

function myFunc(listOrMap: MyType[] | Map<string, MyType>): void {
    // When `noImplicitAny` is on, obj parameter is correctly inferred as `MyType`
    // When `noImplicitAny` is off, obj parameter is inferred as `any`
    listOrMap.forEach((obj) => {
        delete obj.id;
    });
}

πŸ™ Actual behavior

With noImplicitAny=false, the type of the forEach parameter is inferred as any.

πŸ™‚ Expected behavior

With noImplicitAny=false, the type of the forEach parameter is inferred as MyType

Additional information about the issue

Fyi, the type is correctly inferred when noImplicitAny=true, or if not using the union type for myFunc's parameter

@MartinJohns
Copy link
Contributor

This is working as intended: #52748 (comment)

@adamhamlin
Copy link
Author

Ok, thanks for the info @MartinJohns

@adamhamlin adamhamlin closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants