I have multiple functions that get the same type but return a different type of interface. I want to create a type for those functions, but when I write:
const f: (arg: number) => Object = func;
I get an error: Type (arg: number) => SomeInteface is not assignable to type (arg: number) => Object
I could just use (arg: number) => any but I kind of defeats the whole purpose of it being typed.
I just want it to accept all Objects and not just a specific interface because I have plenty.
For example, I'm implementing communication protocols:
interface splPacket {
serviceType: number,
serviceSubType: number,
satelliteTime: Date,
data: Buffer
}
function decodeSpl(input: Buffer): splPacket {...}
function encodeSpl(input: splPacket): Buffer {...}
const spl = {
decode: decodeSpl,
encode: encodeSpl
};
interface ax25Packet {
destCallsign: string,
destSSID: number,
srcCallsign: string,
srcSSID: number,
data: Buffer
}
function decodeAx25(input: Buffer): ax25Packet {...}
function encodeAx25(input: ax25Packet): Buffer {...}
const ax25 = {
decode: decodeAx25,
encode: encodeAx25
};
interface commProtcol {
decode: (input: Buffer): Object;
encode: (input: Object): Buffer;
};
const protocol: commProtocol = spl;
But spl and ax25 won't be assignable to commProtocol.
I want to create an interface that will allow all my communication protocols implementations.
What should I do?
objectwork for you? Notice lower caseobjectstill doesn't work