Reputation: 1026
I have error
Type 'string' is not assignable to type '() => string'
this.selectedValue.display = headerOcr.author.profession;
private selectedValue: IDocumentType = {
id: '1',
display: () => '',
label: ''
}
this is are default initialized value for "selectedValue"
What I should do to headerOcr.author.profession
? display; () => ''
should have const type.
Upvotes: 2
Views: 123
Reputation: 16384
Type 'string' is not assignable to type '() => string'
Typescript expect that all of your object properties will be strings, so there are two ways:
display: () => return '',
IDocumentType
interface like this:IDocumentType {
/*...*/
display: () => string
/*...*/
}
Upvotes: 2
Reputation: 37604
You can not pass a function if you defined it as a string
type. Either you change the definition of headerOcr
or evaluate the function call before passing it to display.
The change of definition would look like these:
IDocumentType {
display: () => string
}
With that you have to use it as IDocumentType.display()
Upvotes: 2