I know of type union & type intersection in type script but I couldn't find a syntax or workaround to use type exclusion. Is there a way to do that?
type ValidIndices = string ^ '_reservedProperty'; // All strings but '_reservedProperty'
interface MyInterface {
[property: ValidIndices]: number;
_reservedProperty: any;
}
It's not a fully answer. But if you want to set exclusion for contsructor params you can use code like this:
declare type Params<T, K extends keyof T = never, D extends keyof T = never> = (
{[P in K]: T[P]} &
{[P in keyof T]?: T[P]} &
{[P in D]?: undefined }
)
...
class Control{
prop1: number
prop2: number
prop3: number
prop4: number
constructor(params: Params<Control, 'prop1' | 'prop2', 'prop4'>){
Object.assign(this, params)
...
And you get:
params: {
prop1: number
prop2: number
prop3?: number
prop4?: undefined
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With