I want to type my variable to accept only type name specific arr of objects but the problem I have that when e.g I declare
object and declare one property then the second one property e.g type TS is showing me all possible values.
Of course if I choose wrong name type values then TS works but can I achieve more stricter value?
{
name: 'Bar',
type:'' // vscode autocompletion is showing my all type values 'master' 'mobilepayment'...
// in this scenario I would want only to see 'cash'
}
type IPaymentMethod =
| {
type: 'master';
name: 'Mastercard';
}
| {
type: 'mobilepayment';
name: 'Mobile Payment';
}
| {
type: 'cash';
name: 'Bar';
}
| {
type: 'maestro';
name: 'EC/Maestro';
}
| {
type: 'visa';
name: 'Visa';
};
const a: IPaymentMethod[] = [
{
name: 'Bar',
type:''
}
]