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

camelcaseKeys return key types on camelcase without exclude prop. #83

Open
serjo96 opened this issue Jan 16, 2022 · 2 comments
Open

camelcaseKeys return key types on camelcase without exclude prop. #83

serjo96 opened this issue Jan 16, 2022 · 2 comments

Comments

@serjo96
Copy link

serjo96 commented Jan 16, 2022

I have class with types for my object and I using convert to camel case like that with exclude keys:

camelcaseKeys(data, { exclude: ['iso_639_1', 'iso_3166_1'], deep: true });

Data after formatting camelcaseKeys is normal, but ts see like iso keys on camel cases to iso6391.
image

export declare class MovieDetails {
  id: number;
  budget: number;
  imdb_id: string | null;
  images: Images
  genres: Genre[];
  spoken_languages: Language[];
  overview: string | null;
  poster_path: string | null;
  production_companies: Company[];
  production_countries: Country[];
  revenue: number;
  runtime: number;
  status: string;
  tagline: string;
  belongs_to_collection: Collection | null;
  title: string;
  homepage: string | null;
  original_title: string;
  adult: boolean;
  release_date: string;
  keywords: {
    keywords: Keyword[];
  };

  credits: MovieCredits;
  lists: ListData<MovieListItem>;
  videos: Videos;
  recommendations: ListData<MoviesListItem>;
  backdrop_path: string;
  original_language: string;
  popularity: number;
  vote_count: number;
  video: boolean;

  vote_average: number;
}

export declare class Language {
  iso_639_1: string;
  name: string;
}

export declare class Images {
  backdrops: Image[];
  posters: Image[];
  logos: Image[];
}

export declare class Image {
  aspect_ratio: number;
  file_path: string;
  height: number;
  iso_639_1: string | null;
  vote_average: number;
  vote_count: number;
  width: number;
}

and etc...

Maybe add some generic only for return type, not only one generic for input and return type?
image

@sindresorhus
Copy link
Owner

// @g-plane

@yutak23
Copy link
Contributor

yutak23 commented Jun 21, 2023

I think as const is required.
(add as const , then your ['iso_639_1', 'iso_3166_1'] can be of type ['iso_639_1', 'iso_3166_1'], rather than string[])

Refer to: https://github.com/sindresorhus/camelcase-keys/blob/v8.0.2/index.test-d.ts#L84

TS reference : https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions

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