Ensure Option<None> of different type evaluates to None (#4647)
This commit is contained in:
@@ -43,6 +43,16 @@ describe('Option', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can convert between different Some/None', (): void => {
|
||||
const def = '{ "foo":"Text", "zar":"Text" }';
|
||||
const none = new Option(registry, def, null);
|
||||
const some = new Option(registry, def, new Option(registry, def, { foo: 'a', zar: 'b' }));
|
||||
|
||||
expect(new Option(registry, def, none).isNone).toBe(true);
|
||||
expect(new Option(registry, def, some).isNone).toBe(false);
|
||||
expect(new Option(registry, def, some).unwrap().toHuman()).toEqual({ foo: 'a', zar: 'b' });
|
||||
});
|
||||
|
||||
it('correctly handles booleans', (): void => {
|
||||
expect(new Option(registry, bool).isNone).toBe(true);
|
||||
expect(new Option(registry, bool, true).isSome).toBe(true);
|
||||
|
||||
@@ -25,7 +25,7 @@ function decodeOption (registry: Registry, Type: CodecClass, value?: unknown): C
|
||||
value = value.value;
|
||||
}
|
||||
|
||||
if (isNull(value) || isUndefined(value) || value === '0x') {
|
||||
if (isNull(value) || isUndefined(value) || value === '0x' || value instanceof None) {
|
||||
return new None(registry);
|
||||
} else if (value instanceof Type) {
|
||||
// don't re-create, use as it (which also caters for derived types)
|
||||
|
||||
Reference in New Issue
Block a user