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

GenerateMetadataError: Unknown type: IndexedAccessType #1622

Open
2 of 4 tasks
douglasg14b opened this issue May 3, 2024 · 3 comments
Open
2 of 4 tasks

GenerateMetadataError: Unknown type: IndexedAccessType #1622

douglasg14b opened this issue May 3, 2024 · 3 comments

Comments

@douglasg14b
Copy link

douglasg14b commented May 3, 2024

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

I found several referneced, but they all appeard to be fixed...?

Expected Behavior

When I tun tsoa routes the following controller fails:

export type BaseIVR3Config = {
    walkingSkeletonPath: WalkingSkeletonPath;
    bestMovies: BestMovies;
};

export type BaseIVR3ConfigKey = keyof BaseIVR3Config;
export type BaseIVR3ConfigValue = BaseIVR3Config[BaseIVR3ConfigKey]; // WalkingSkeletonPath | BestMovies

type WalkingSkeletonPath = 'A' | 'B';
type BestMovies = {
    title: string;
    year: number;
}[];

@Route('config2')
export class Config2Controller extends Controller {
    constructor(private useCases: ConfigUseCases) {
        super();
    }

    @Get('{key}')
    async getByKey(@Path() key: BaseIVR3ConfigKey): Promise<BaseIVR3ConfigValue | 'error'> {
        const result = await this.useCases.getByKey(key);

        if (result.ok) {
            return result.value.value;
        }

        return 'error';
    }
}

Current Behavior

This fails with:

Generate routes error.
GenerateMetadataError: Unknown type: IndexedAccessType
This was caused by 'BaseIVR3Config[BaseIVR3ConfigKey] | 'error''

Possible Solution

Unknown

Steps to Reproduce

Use the above code with tsoa

Context (Environment)

Version of the library: 6.2.1
Version of NodeJS: 18.13.0

  • Confirm you were using yarn not npm: [ ]
    • We are using pnpm

Detailed Description

N/A See above

Breaking change?

Copy link

github-actions bot commented May 3, 2024

Hello there douglasg14b 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@douglasg14b
Copy link
Author

douglasg14b commented May 3, 2024

Oh, found another, is this the same problem? I see other issues like this that appear to be solved 🤔

Indexed types like this make up a majority of any typings we have when it comes to configuration or definitions. It's almost impossible to avoid index types through the entire type tree as they are a fundamental part of most TS usage.

Is there any particular reason that: type Response = WalkingSkeletonPath | BestMovies is fine but type Response = BaseIVR3Config[BaseIVR3ConfigKey] does not even though they are both union types?

#1375

@douglasg14b
Copy link
Author

Hm, this is actually causing a lot of pain at multiple layers, I wonder how to work around it.

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

1 participant