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

Question: ExclusiveArray #345

Closed
chris-schra opened this issue Jan 6, 2022 · 2 comments
Closed

Question: ExclusiveArray #345

chris-schra opened this issue Jan 6, 2022 · 2 comments

Comments

@chris-schra
Copy link

Dear All,

I'm not even sure if it is possible, but a lot of times we convert Props to Array. Use case: imagine a "Cached Model":

export class CachedModel {
  id: CacheIdentifier<number>;
  locale: CacheIdentifier<string>;
  noIdentifier: string;
}

I can already extract the keys:
type ExtractCacheIdentifierKeys<Model extends CachedModel> = ConditionalKeys<Model, CacheIdentifier<string | number>>;

But what if I need to construct an array of all the keys? Like

const cacheIdentifiersToUse:Array<ExtractCacheIdentifierKeys<CachedModel>> = ["id","id"]

How would it be possible to make sure that each key of ExtractedKeys does only exist once in the array?

@sindresorhus
Copy link
Owner

How would it be possible to make sure that each key of ExtractedKeys does only exist once in the array?

Sounds like you should be using a Set.

@chris-schra
Copy link
Author

Oh what a shame… absolutely correct… I‘ll better leave now 😂

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

2 participants