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

Why does keys() not work with dynamic inputs? #38

Closed
niksrid opened this issue Jul 1, 2020 · 2 comments
Closed

Why does keys() not work with dynamic inputs? #38

niksrid opened this issue Jul 1, 2020 · 2 comments

Comments

@niksrid
Copy link

niksrid commented Jul 1, 2020

Hello,

I was just wondering why does the keys function not work with dynamic names passed to it?

Is this because of an inherent TypeScript limitation or is it a transformation function limitation?

For reference, this is what my code roughly looks like right now but does not seem to work
const instances = ['a','b','c'];
for(let instance of instances){
let instanceKeys = keys<NexusPrismaTypes[instance]>();
console.log(instanceKeys) //Returns an empty array
}

@kimamula
Copy link
Owner

kimamula commented Jul 1, 2020

I think you just missed typeof. This should work:

const instances = ['a','b','c'];
for(let instance of instances){
  // add typeof in front of instance
  let instanceKeys = keys<NexusPrismaTypes[typeof instance]>();
  console.log(instanceKeys);
}

@kimamula
Copy link
Owner

kimamula commented Jul 1, 2020

Probably you also need as const.

// add 'as const'
const instances = ['a','b','c'] as const;
for(let instance of instances){
  // add typeof in front of instance
  let instanceKeys = keys<NexusPrismaTypes[typeof instance]>();
  console.log(instanceKeys);
}

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