Is there a way to override the property type from a library declaration? I attempted to do so using an interface but received an error stating
Subsequent property declarations must have the same type
. How can this issue be resolved?
// Library Declaration
declare class Auth {
user: Record<string, string | number> | null
// I want to remove the null type in the user property without needing to use `non-null assertion` in line 21
// Changing this file is not possible as it is a third-party library
}
// ------------------------------
// Our File
// My Attempt at Overriding the Interface, which failed
interface Auth {
user: Record<string, string | number>
}
const a: Auth = {
user: {
name: 'joko',
age: 30
}
}
const userName = a.user!.name
// const userName = a.user.name // <-- I wish to use this syntax to access properties without worries
I tried to override the library declaration using an interface but was unsuccessful. My desired outcome is to be able to override the type without modifying the original library code, solely through our own code.