Typescript-TDD / ts-auto-mock

Typescript transformer to unlock automatic mock creation for interfaces and classes
https://typescript-tdd.github.io/ts-auto-mock
MIT License
597 stars 16 forks source link

Type errors with nested mocks after Typescript 5 upgrade #1469

Closed hoi4 closed 1 year ago

hoi4 commented 1 year ago

@uittorio Most of our tests work like a charm with the new version. Thank you the amazingly quick release.

There seems to be a problem with nested mocks though 🤔

Example:

const summaryImages: SummaryImage[] = createMockList<SummaryImage>(2, (index: number) => {
  return {
    id: index,
    source: `source-for-id-${index}`,
  };
});

const test = createMock<Summary>({ summaryImages })

The error is Type 'SummaryImage[]' is not assignable to type 'PartialObjectDeep<SummaryImage[]>.

Your environment

uittorio commented 1 year ago

I had a quick look and it seems related to how we do deep partisl for functions. I think for now you could ignore the error with ts ignore but I will see if I can find a fix for it

hoi4 commented 1 year ago

Would be awesome to have a fix for this to avoid using ts-ignore 😅

uittorio commented 1 year ago

I know 😂! I will have another look tonight!

itzsaga commented 1 year ago

Also have hit this.

dcook-hsi commented 1 year ago

Same here. My projects have a lot of nested mocks so a fix for this would be amazing!

uittorio commented 1 year ago

Sorry for the delay, I have a fix!! release soon! I've just copied the partial deep utilities from another library!

uittorio commented 1 year ago

You might try now https://github.com/Typescript-TDD/ts-auto-mock/releases/tag/3.7.1

dcook-hsi commented 1 year ago

That seems to have resolved the issue for me. Thank you!

hoi4 commented 1 year ago

@uittorio Works like a charm. Thank you so much! 🎉