Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping attributes in inherited types fails to convert #38

Open
Defrosted opened this issue Sep 4, 2023 · 2 comments
Open

Overlapping attributes in inherited types fails to convert #38

Defrosted opened this issue Sep 4, 2023 · 2 comments

Comments

@Defrosted
Copy link

Defrosted commented Sep 4, 2023

Hi! Thanks for creating this tool, it's been a life saviour for us for generating OpenAPI definitions. We want to have a single source of truth for our type definitions, so a tool like this comes pretty handy.

However, I found an issue when type converting interfaces that inherit from other interfaces that share common attributes.

Let's imagine we have the following declarations:

interface Base {
  $type: string;
  comment: string;
}

interface A {
  $type: 'a';
  a: string;
}

export interface Foo extends Base, A {
  $type: 'a';
}

The conversion works as expected. However, if interface A has declared an attribute that matches one in the Base interface, the CLI gives an error Cannot read properties of undefined (reading 'length'). With a bit of testing I was able to narrow the issue down to the changes version 2.3.0. Previous versions have no issues with converting this, though, looking at the release notes it's supposedly because they weren't being converted at all 😄

Here's a modified example of the one above that reproduces the error:

interface Base {
  $type: string;
  comment: string;
}

interface A {
  $type: 'a';
  a: string;
  comment: string;
}

export interface Foo extends Base, A {
  $type: 'a';
}

Consideration for debugging: it would be nice to be able to see where the errors are generated from. The error didn't output any information regarding file or line number in regards to what was producing it. My project has quite extensive types that are converted using typeconv, so it took a while to find what was causing the error.

@AnotherToaster
Copy link

I ran in to the samen issue with the same error message Cannot read properties of undefined (reading 'length')

export type B = {
	testB: string;
};

export type A = B & {
	testA: string;
};

Worked perfectly with version 1.8.0

@trevorpfiz
Copy link

trevorpfiz commented Dec 10, 2023

I am getting the same error. Definitely 2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants