Skip to content

Commit

Permalink
Add undefined to return type of PropertyValues.get() (#3710)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfagnani authored May 8, 2023
1 parent cabadd7 commit 0994923
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-baboons-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit/reactive-element': patch
---

Add `undefined` to the return type of PropertyValues.get()
2 changes: 1 addition & 1 deletion packages/reactive-element/src/reactive-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export type PropertyValues<T = any> = T extends object
// This type must be exported such that JavaScript generated by the Google
// Closure Compiler can import a type reference.
export interface PropertyValueMap<T> extends Map<PropertyKey, unknown> {
get<K extends keyof T>(k: K): T[K];
get<K extends keyof T>(k: K): T[K] | undefined;
set<K extends keyof T>(key: K, value: T[K]): this;
has<K extends keyof T>(k: K): boolean;
delete<K extends keyof T>(k: K): boolean;
Expand Down
6 changes: 3 additions & 3 deletions packages/reactive-element/src/test/reactive-element_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3233,7 +3233,7 @@ suite('ReactiveElement', () => {
changedProperties.set('foo', 'hi');

// This should type-check without a cast:
const x: number = changedProperties.get('foo');
const x: number | undefined = changedProperties.get('foo');
changedProperties.set('foo', 2);

// This should type-check without a cast:
Expand Down Expand Up @@ -3295,7 +3295,7 @@ suite('ReactiveElement', () => {
class A extends ReactiveElement {
foo!: number;
override update(changedProperties: PropertyValues<A>) {
const n: number = changedProperties.get('foo');
const n: number | undefined = changedProperties.get('foo');
if (n) {
//Suppress no-unused-vars warnings
}
Expand All @@ -3304,7 +3304,7 @@ suite('ReactiveElement', () => {
class B extends A {
bar!: string;
override update(changedProperties: PropertyValues<B>) {
const s: string = changedProperties.get('bar');
const s: string | undefined = changedProperties.get('bar');
if (s) {
//Suppress no-unused-vars warnings
}
Expand Down

0 comments on commit 0994923

Please sign in to comment.