-
Notifications
You must be signed in to change notification settings - Fork 32
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
Interface-handling regression in 5.4.7? #138
Comments
We are getting this problem too. microsoft/TypeScript#50087 (comment) likely explains this. Maybe the |
The following problems recur when using I think the essence of the error lies in the index signature part. The following methods may help. |
Hi @yutak23 , thanks for the solution, it works for my case! However, after diving deep into this issue, I think the fix for #116 in #117 is inaccurate because the use of As a result, it breaks nested classes: class Foo {
someVar = 1
someMethod() {}
}
const a = snakecaseKeys({ foo: new Foo() })
// the type is { foo: Foo }
// the value is { foo: { some_var: 1 } } As well as nested interfaces: interface Bar {
someVar: number
}
const bar: Bar = { someVar: 1 }
const b = snakecaseKeys({ bar })
// the type is { bar: Bar }
// the value is { bar: { some_var: 1 } } So I still think As for removing functions from the object (a fix for #116), I believe a simple condition will do the trick: type WithoutFunctions<T extends Record<string, any>> = {
[K in keyof T as T[K] extends Function ? never : K]: T[K]
}
type _Date = WithoutFunctions<Date>
// {}
type _Error = WithoutFunctions<Error>
// { name: string; message: string; stack?: string | undefined; } |
I believe that using this library to change the case of object other than plain object, such as instances of a class or function, is not the intended use of the library. Although the readme simply mentions object, I think it specifically refers to plain object. This can be understood by looking at the readme of camelcase-keys, a similar library to snakecase-keys. |
Hey, first of all thanks for developing this library.
We bumped into an interesting TS compilation problem when trying to upgrade from 5.4.6 to 6.0.0, I narrowed it down to version 5.4.7 and this commit: 3ab58ee.
I'm not entirely sure if we're doing something wrong or is there an actual regression.
A piece of code to reproduce the problem:
With snakecase-keys 5.4.6 it compiles as expected.
With 5.4.7 it fails to compile:
TS version: 5.3.2
Happy to provide more details if that helps.
The text was updated successfully, but these errors were encountered: