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

[BUG] TypeScript (fetch) client causes TS7053 #19011

Open
falk-stefan opened this issue Jun 24, 2024 · 2 comments
Open

[BUG] TypeScript (fetch) client causes TS7053 #19011

falk-stefan opened this issue Jun 24, 2024 · 2 comments

Comments

@falk-stefan
Copy link

It looks like the previous issue I had (#18446) was resolved, but, unfortunately, I am still not able to upgrade.

My local setup give me the following type error:

TS7053: Element implicitly has an any type because expression of type string can't be used to index type

The reason is that key is ont being cast to its correct type:

export function instanceOfAuthError(value: any): boolean {
    for (const key in AuthError) {
        if (Object.prototype.hasOwnProperty.call(AuthError, key)) {
            if (AuthError[key] === value) {
                ^^^^^^^^^^^^^^^^^^^^^^^^
                return true;
            }
        }
    }
    return false;
}

an explicit cast would be necessary:

if (AuthError[key as keyof typeof AuthError] === value) {
  return true;
}

openapi.json

{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.6.0"
  }
}

Generated model AuthError.ts (full)

/* tslint:disable */
/* eslint-disable */
/**
 * backend-sequelize
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 0.0.1
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

/**
 *
 * @export
 */
export const AuthError = {
  AuthTokenExpired: 'auth/token-expired',
} as const;
export type AuthError = (typeof AuthError)[keyof typeof AuthError];

export function instanceOfAuthError(value: any): boolean {
  for (const key in AuthError) {
    if (Object.prototype.hasOwnProperty.call(AuthError, key)) {
      if (AuthError[key] === value) {
        return true;
      }
    }
  }
  return false;
}

export function AuthErrorFromJSON(json: any): AuthError {
  return AuthErrorFromJSONTyped(json, false);
}

export function AuthErrorFromJSONTyped(json: any, ignoreDiscriminator: boolean): AuthError {
  return json as AuthError;
}

export function AuthErrorToJSON(value?: AuthError | null): any {
  return value as any;
}
@sir4ur0n
Copy link

sir4ur0n commented Jul 8, 2024

Isn't it a duplicate of #18746 ?

@hhvrc
Copy link
Contributor

hhvrc commented Aug 13, 2024

This is a duplicate, already been implemented, pending release at next version of oapi-generator

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

No branches or pull requests

3 participants