kbrabrand / camelize-ts

A typescript typed camelCase function that recursively camel cases a snake cased object structure
22 stars 6 forks source link

objects with camelCase keys are lowercased in the type #18

Closed nicangeli closed 2 years ago

nicangeli commented 2 years ago

When you camelize an object with some camelCased keys, the generated type of these keys is lowercased

See:

it("objects with some camelCase keys", () => {
    const camelized = camelize({
      aKey: {
        b: { a_key: 123 },
      },
    });

    // this is a ts error, but the object camelized is correct
    expect(camelized.aKey.b.aKey).toEqual(123);

    // this resolves the ts error, but now camelized.akey is undefined)
    expect(camelized.akey.b.aKey).toEqual(123);
  });
kbrabrand commented 2 years ago

@nicangeli I finally got around to this one. I won't ask why your object contains both camel cased and snake cased stuff 😅, but it's a good catch – there's a discrepancy between the return type and the actual data.

I believe #22 should fix this. Would you care to test it

kbrabrand commented 2 years ago

@jonkoops Any thoughts here? The issue pointed out by @nicangeli is real, so this change should be transparent to anyone with snake cased stuff only, and affects only those with a mix of snake/pascal/camel case.