Skip to content

fix: adjust types in autocomplete-display-example #9240

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

Merged
merged 1 commit into from
Jan 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class AutocompleteDisplayExample {
ngOnInit() {
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith({} as User),
map(user => user && typeof user === 'object' ? user.name : user),
startWith<string | User>(''),
map(value => typeof value === 'string' ? value : value.name),
map(name => name ? this.filter(name) : this.options.slice())
);
}
Expand All @@ -42,8 +42,8 @@ export class AutocompleteDisplayExample {
option.name.toLowerCase().indexOf(name.toLowerCase()) === 0);
}

displayFn(user: User): string {
return user ? user.name : user;
displayFn(user?: User): string | undefined {
return user ? user.name : undefined;
Copy link
Contributor Author

@rafaelss95 rafaelss95 Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was doing the following:

displayFn(user?: User): string | undefined {
  return user ? user.name : user; <---
}

... however it doesn't go well in Stackblitz (maybe because there we don't have strictNullChecks).

}

}