I am currently working on defining a new interface
interface SUser {
ID: number;
NAME: string;
MAIL: string;
PASSWORD: string;
GENDER: number;
BIRTHDATE: string;
ID_FB: string;
CREDIT: number;
ID_REFERRAL: number;
}
My objective is to create a type that accurately describes an object while ensuring that it aligns with the key and value structure of my interface properties.
In attempting to achieve this, I experimented with the following code:
type fieldType = { [K in SUser]: string | number };
This setup allows me to restrict a field object to only accept keys from the SUser
interface. However, I encountered a challenge where I would like to receive an error if I try to assign a string value to a key like ID
.
Essentially, I want to enforce a strict key-value pairing based on the defined interface.
Despite my efforts, when implementing the above code, I faced the following error message indicating that the enforcement of value types was not successful:
Type 'SUser' is not assignable to type 'string | number | symbol'.
Type 'SUser' is not assignable to type 'symbol'.
Would appreciate any guidance or assistance regarding this matter.