Suppose we have a type like:
type Requirement = {
name: string;
}
And an object conforming to this Requirement type:
let some_requirement: Requirement = {
name: 'SomeRequirement'
}
Now suppose we want to use typeof some_requirement to enforce another type to match its string literal name
type RequirementAssociate<R extends Requirement> = {
name: R['name']
}
let some_requirement_associate: RequirementAssociate<typeof some_requirement> = {
name: 'SomeRequirement' // Enforce this to have the same name as some_requirement
}
In the above example, TypeScript will enforce that some_requirement_associate.name is a string, but will not enforce that it is the string literal 'SomeRequirement'
Generally, how can we ensure an object is compatible with a type (some_requirement: Requirement), while working with its "specific" type (not sure the term for this), like in the case of enforcing some_requirement_associate.name is the string literal SomeRequirement above
satisfiesoperator