framework7io / framework7

Full featured HTML framework for building iOS & Android apps
http://framework7.io
MIT License
18.06k stars 3.23k forks source link

Improve types #4101

Open AlexRMU opened 1 year ago

AlexRMU commented 1 year ago
<!-- svelte -->
<!-- same -->
<Button large={true} small={true}>Button</Button>
<Button small={true}>Button</Button>
<!-- same -->
<Button outline={true} fill={true}>Button</Button>
<Button fill={true}>Button</Button>

This applies to many components.

Is your feature request related to a problem? Please describe. No.

Describe the solution you'd like Use unions, intersection, etc. so that the types match the code.

type OldButton = {
    text: string;
    /* ...other */
    large: boolean;
    small: boolean;
};
let old_button: OldButton = {
    text: "",
    /* ...other */
    large: true,
    small: true,
};

type NewButton = {
    text: string;
    /* ...other */
} & ({ large: true; small?: false } | { large?: false; small: true });
let new_button1: NewButton = { //error
    text: "",
    /* ...other */
    large: true,
    small: true,
};
let new_button2: NewButton = {
    text: "",
    /* ...other */
    large: true,
};
let new_button3: NewButton = {
    text: "",
    /* ...other */
    small: true,
};
let new_button4: NewButton = {
    text: "",
    /* ...other */
    large: false,
    small: true,
};

Describe alternatives you've considered Write about all such cases in the documentation.

Additional context This will help us better understand how the framework works and what properties components need.