Here is my sample code:
const AUSTRIA = ['Vienna', 'Raiding'] as const;
const testCountries = { Austria: AUSTRIA } as const;
type CountryType = typeof testCountries;
type CountryStateType<T extends CountryType> = [keyof T, T[keyof T][number]];
const countryAndState: CountryStateType<CountryType> = ['Austria', 'Raiding'];
This is working, and this is the expected behavior for countryAndState[1]
referencing the CountryStateType
:
Here is the image: TypeScriptLintError Image
const StateBasedOnCountry: CountryType['Austria'][number] = 'Raiding';
New contributor
Gian Carlo Carranza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.