Make convertAttributeNameToForm type-safe (#3869)

This commit is contained in:
Jon Koops 2022-11-25 15:58:10 +01:00 committed by GitHub
parent 69fa367bf9
commit 7dec66edfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -82,9 +82,11 @@ const isAttributeArray = (value: any) => {
const isEmpty = (obj: any) => Object.keys(obj).length === 0;
export const convertAttributeNameToForm = (name: string) => {
export const convertAttributeNameToForm = <T extends string>(name: T) => {
const index = name.indexOf(".");
return `${name.substring(0, index)}.${beerify(name.substring(index + 1))}`;
return `${name.substring(0, index)}.${beerify(
name.substring(index + 1)
)}` as ReplaceString<T, ".", "🍺", { skipFirst: true }>;
};
const beerify = <T extends string>(name: T) =>