Skip to content

README: in-memory database example issue with getUserByUsername #24

@ferdinandlist

Description

@ferdinandlist

Tiny issue:
Usernames are always available for me using this example as a found user is returned to nowhere?

export function getUserByUsername(username: string) {
  users.forEach((user) => {
    if (user.username === username) {
      return user; // returns to nowhere as far as I can see
    }
  });
  return null;
}

The following change fixes it for me:

export function getUserByUsername(username: string): User | null {

	let foundUser = null;

	users.forEach((user) => {
		if (user.username === username) {
			foundUser = user;
		}
	});

	return foundUser;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions