I want to utilize the never type in TypeScript to ensure that I have covered all possible implementations of an interface. Check out the code snippet here.
interface MyInterface {
a: string;
b: number;
}
class MyClass1 implements MyInterface {
a: string;
b: number;
constructor() { }
}
class MyClass2 implements MyInterface {
a: string;
b: number;
constructor() { }
}
function foo(arg: MyInterface) {
if (arg instanceof MyClass1) {
} else if (arg instanceof MyClass2) {
} else {
assertNever(arg);
}
}
function assertNever(value: never): never {
throw Error(`Unexpected value '${value}'`);
}
However, I encountered an error stating: Argument of type 'MyInterface' is not assignable to parameter of type 'never'.
Any suggestions on how to resolve this issue?