Reputation: 65
How to pass an object of immutable type to a function as an argument
interface ImmutableObject<T> {
get<K extends keyof T>(name: K): T[K],
set<S>(o: S): Immutable<T & S>,
"value1": string,
}
function(values: ImmutableObject) {
//.. doo stuff
}
I'm getting an error
'ImmutableObject' requires 1 type argument(s).
Upvotes: 2
Views: 448
Reputation: 1436
Let your function pass through type parameter of immutable object.
function <T>(values: ImmutableObject<T>) {
//.. doo stuff
}
Upvotes: 0
Reputation: 249466
ImmutableObject
is a generic interface. The actual data of the object is determined by the T
parameter. You need to specify the T
argument to the immutable object
interface ImmutableObject<T> {
get<K extends keyof T>(name: K): T[K],
set<S>(o: S): Immutable<T & S>,
}
function foo(values: ImmutableObject<{ value1: string }>) {
values.get('value1')
}
Upvotes: 2