Skip to content

createHydratedMock() should return Required<T> #1494

Description

@hosswald

Subject of the issue

createHydratedMock() mocks optional properties. The typescript compiler should know about that to avoid having to write unnecessary as any in tests.

Your environment

  • ts-auto-mock version: 3.7.1
  • typescript version: 5.1.6
  • node version: 20.5.0
  • npm version: 9.8.1

Expected behavior

    const foo = createHydratedMock<{bar?: string}>() // typeof foo == Required<{bar?: string} == {bar: string}
    const baz: string = foo.bar

Actual behavior

    const foo = createHydratedMock<{bar?: string}>()
    const baz: string = foo.bar // TS2322: Type 'string | undefined' is not assignable to type 'string'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions