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

CamelCase<string> is of type 'never' ? #392

Closed
GMartigny opened this issue Apr 21, 2022 · 2 comments
Closed

CamelCase<string> is of type 'never' ? #392

GMartigny opened this issue Apr 21, 2022 · 2 comments

Comments

@GMartigny
Copy link

I might be misusing the CamelCase type, but I have an error "TS2322: Type 'string' is not assignable to type 'never'." with that very simple toCamelCase function.

import { CamelCase } from 'type-fest';

function toCamelCase (string: string): CamelCase<string> {
    return string.replace(/_(.)/g, (_, $1) => $1.toUpperCase());
}

Playground Link

What's wrong here ?

@sindresorhus
Copy link
Owner

You need to use generics: Playground Link

@GMartigny
Copy link
Author

Thanks a lot ! 🙇‍♂️

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