I declared a Typescript interface like so:
interface ProductFieldMapping {
name: string,
mapping: (p: Product) => string | number,
formatting: <T>(t: T) => T,
}
And a function that returns a list of such fields like so:
export const mappingFunctions = (host: string): ProductFieldMapping[] => {
const mappings = defaultFunctions(host)
return [
{
name: 'title',
mapping: mappings.productName,
formatting: (s: string) => s,
},
]
}
But I get this error when I want to assign to formatting this simple function (s: string) => s
Type '(s: string) => string' is not assignable to type '<T>(t: T) =>
T'.
What am I missing?
Possible fix:
type MappingResult = | string | number
interface ProductFieldMapping<T> {
name: string,
mapping: (p: Product) => T,
formatting: (t: T) => T,
}
export const mappingFunctions = (host: string): ProductFieldMapping<MappingResult>[] => {
const mappings = defaultFunctions(host)
return [
{
name: 'title',
mapping: mappings.productName,
formatting: compose([limitSize(255), replaceNewLine(' ')]),
}]
}