Skip to content

[Bug] '&' keyword Type recognition bug when used with array methods #49239

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

Closed
rhkdgns95 opened this issue May 25, 2022 · 3 comments
Closed

[Bug] '&' keyword Type recognition bug when used with array methods #49239

rhkdgns95 opened this issue May 25, 2022 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@rhkdgns95
Copy link

rhkdgns95 commented May 25, 2022

Bug Report

🔎 Search Terms

Generic Type Array & keyword map method

🕗 Version & Regression Information

"typescript": "^4.4.3"

💻 Code

interface ITool {
  name: string;
  count: number;
}

interface IUser {
  name: string
  age: number;
  tools: ITool[];
}

const users: Array<
  IUser & { uid: number; tools: Array<ITool & { uid: number }> }
> = [
  {
    uid: 1,
    name: "Brian",
    age: 29,
    tools: [
      {
        uid: 1,
        name: "pen",
        count: 1,
      },
      {
        uid: 2,
        name: "book",
        count: 20,
      },
    ],
  },
];

users.map(user => {
  // Ok
  console.log('user.uid: ', user.tools[0].uid);
  
  user.tools.map(tool => {
    // Error
    console.log('tool.uid: ', tool.uid);
  });

  return user;
})

🙁 Actual behavior

bug1
bug2

ezgif com-gif-maker

🙂 Expected behavior

In the normal case, the uid field within the array (of 'users' or 'tools') should be resolvable.

@rhkdgns95 rhkdgns95 changed the title Bug when using '&' keyword together with generic array type [Bug] '&' keyword Type recognition bug when used with array methods May 25, 2022
@MartinJohns
Copy link
Contributor

Most likely a duplicate of #41874.

@rhkdgns95
Copy link
Author

rhkdgns95 commented May 25, 2022

@MartinJohns

Yes, it has been confirmed with a similar issue!

In the current issue, when using the array method (ex. .forEach(), .map() etc...), there is a compile error problem saying that the field of the corresponding element value cannot be referenced.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 26, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants