To answer you explicit question: You technically can't do what you want yet.
Type Mapping will create a Type
not an interface -- Readonly<T>
is a built in type mapper that will return a Type
. You cannot implement or extend Type
aliases, only interface / class.
thus:
interface PersonReadonly extends Readonly<Person> {}
is invalid until support for implementing types are done, if ever.
That doesn't stop you passing around the Type though; and you can use union on types to build up more complex types too. thus you can do:
type PersonWithState = Readonly<Person> & { state: string }
let person = <Person>{ name: "John", age: 20 };
let personState = <PersonWithState>{ ...person, state: "online" };
personState.age = "30"; // error;
personState.state = "offline"; // OK.
but you cannot have a class implement, or interface extend, PersonWithState
- yet.