conf icon indicating copy to clipboard operation
conf copied to clipboard

onDidChange doesn't support dot-notation for nested properties

Open hdhilip98 opened this issue 2 years ago • 0 comments

I get a typescript compilation error when I try to pass in a key with dot-notation to the onDidChange method. This seems to happen because the type of key the onDidChange method is expecting is keyof <StoreType>. This doesn't include the nested object properties.

Requesting to add an overload that takes a key of type string. Just like the get or set.

Thanks!

interface Config {
  foo: Foo;
};

interface Foo {
  bar: string;
};

export const defaults: Config = {
  foo: {
    bar: "foobar"
  }
};

const store = new Store<Config>({
  defaults,
});

// ERROR - Argument of type '"foo.bar"' is not assignable to parameter of type 'keyof Config'.
store.onDidChange('foo.bar', (nVal, oVal) => {
  console.log(nVal, oVal);
});

hdhilip98 avatar Jun 16 '22 17:06 hdhilip98