Issue
In my object, have different key
for each of the object. for that how to write generic data type?
here is my try:
interface Dic {
[key:string]:string; // how to write for generic values
age:number;
}
const Object1:Dic = {
name:"name1",
age:0
}
const Object2:Dic = {
village:"name1",
age:40
}
For me it's throws the error. any one help me to understand this kind of scenarios?
Solution
You can do age:any;
or [key:string]:any;
.
Unfortunately in the typescript interface the dynamic property needs to be abstract enough to contain all non-dynamic properties .
Answered By - Sean AH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.