no matter v1 or v2, the payload types defined don't allow for custom fields. it forces us to cast as any to be able to use it, making the value of typescript void. custom fields are a huge part of pipedrive so it's really inconvenient that we can't use them properly.
In hope for a faster path of remediation, I've doodled some type utilities which may achieve custom fields at quite low cost. Here below with comments:
// From https://skalt.github.io/projects/brzozowski_ts/typeHexChar="0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"a"|"b"|"c"|"d"|"e"|"f";typeIsHex<Strextendsstring>=Strextends""
? true
: Strextends `${HexChar}${infer Rest}`
? IsHex<Rest>
: never;// From https://stackoverflow.com/a/73369825typeStringLength<Strextendsstring,Accextends0[]=[]>=Strextends `${string}${infer $Rest}`
? StringLength<$Rest,[...Acc,0]>
: Acc["length"];typeIsLength<Sextendsstring,Lengthextendsnumber>=StringLength<S>extendsLength ? true : false// A custom field id is 40 char hex stringtypeCustomFieldId<Textendsstring>=IsHex<T>extendstrue
? IsLength<T,40>extendstrue
? string
: never
: nevertypeWithCustomFields<T,BaseType>={[KeyinkeyofT]:
Keyextendsstring
? KeyextendskeyofT
? Value[Key]
: CustomFieldId<Key>
: never}// --- Example implementationexporttypeAddOrganizationRequest={'name'?: string;'owner_id'?: number;'add_time'?: string;'update_time'?: string;}// We let arg be broader than AddOrganizationRequest by defining it as extends and pass the basic blueprint as K. This allow to compare and keep types of BaseType untouched and iterate on T and allow extension if some keyof T are CustomFieldIdfunctiontest<TextendsBaseType,BaseType=AddOrganizationRequest>(arg: WithCustomFields<T,BaseType>){}test({name: 'foo',owner_id: 0,add_time: 'foo',update_time: 'foo',['deadbeefdeadbeefdeadbeefdeadbeefdeadbeef']: 'foo',// allowed})test({name: 'foo',owner_id: 0,add_time: 'foo',update_time: 'foo',['qwe']: 'foo',// denied['deadbeefdeadbeefdeadbeefdeadbeefdeadbeef']: 'foo',// allowed})test({name: 'foo',owner_id: 0,add_time: 'foo',update_time: 'foo',['qwe']: 'foo',// denied})
no matter v1 or v2, the payload types defined don't allow for custom fields. it forces us to cast
as anyto be able to use it, making the value of typescript void. custom fields are a huge part of pipedrive so it's really inconvenient that we can't use them properly.In hope for a faster path of remediation, I've doodled some type utilities which may achieve custom fields at quite low cost. Here below with comments: