Skip to content

Properties with optional object with its own optional properties returns empty object #16

Description

@aulonm

Hi!

Given this snippet of code:

const optionalTest = record({
  id: optional(string)
});

const objDecoder = record({
  id: number,
  name: string,
  optionalId: optional(optionalTest),
});
type Obj = decodeType<typeof objDecoder>;

optionalTest returns an empty object when accessing it through objDecoder.

I have used your example code and rewritten it to reproduce the potential bug: https://codesandbox.io/s/typescript-json-decoder-playground-forked-pcx8f7?file=/src/App.tsx

As you can se, typescript complains that id does not exist on an empty object.

Edit: stopped working after upgrading from 1.0.7 to 1.0.10

Is this intentional or a bug? :)

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