I want to write a function with a parameter type guard that accepts the value from a K/V pair from an object or type...
type VodTreeName = {
Movie: 'movie_vod',
TV: 'tv_vod',
VideoStore: 'video_store'
};
function test(something: VodTreeName) {
// expecting something === 'movie_vod'
}
test(VodTreeName.Movie);
// 'VodTreeName' only refers to a type, but is being used as a value here.
--or--
const VodTreeName = {
Movie: 'movie_vod',
TV: 'tv_vod',
VideoStore: 'video_store'
};
function test(something: keyof typeof VodTreeName) {
// expecting something === 'movie_vod'
}
test(VodTreeName.Movie);
// Argument of type 'string' is not assignable to parameter of type '"Movie" | "TV" | "VideoStore"'.
How else can I do this without having a type AND an object that I have to export/import to other modules?