Hello, guys, i have two interfaces that have same name fields but different implementation, but i want when i create new interface without all fields from A in new interface, it should throws an error any help please?
You could then extend those classes another layer to get close to what you're asking for, but keys that are not re-defined will inherit from their parents. I'm assuming this is also not ideal.
class MyStub implements Stub { foo = '' bar = ''}class MySpecialStub extends MyStub { foo = 'hi' // bar = 'bye' // optional, if not defined it's empty string from MyStub}
class MyStub implements Stub { foo = '' bar = ''}class MySpecialStub extends MyStub { foo = 'hi' // bar = 'bye' // optional, if not defined it's empty string from MyStub}
---
You can also do something similar with generics
type A = { a: unknown b: unknown}type B<T extends A> = {}type C = B<{ a: string }> // error: Property 'b' is missing
type A = { a: unknown b: unknown}type B<T extends A> = {}type C = B<{ a: string }> // error: Property 'b' is missing
but then you lose
implements
implements
interface D extends B<{ a: string, b: string }> { c: unknown}class MyThing implements D {} // errors that 'c' is missing, but does not error about 'a' or 'b'
interface D extends B<{ a: string, b: string }> { c: unknown}class MyThing implements D {} // errors that 'c' is missing, but does not error about 'a' or 'b'
---
Maybe someone else will get closer, but if you explain more of your exact scenario there might also be a better pattern for it.
Using runtime errors rather than TS ones could certainly handle this if that's a better compromise. Other languages have virtual classes that get close to this too. I personally avoid classes. Using the types and then defining objects that conform to those types would get you there if you can give up on