ts: union type as well as:? What do you mean

Union type

Joint type represents a value can be one of several types. We use a vertical bar (|) to separate each type, the number | string | boolean represents a value can be a number, string, or boolean.

function padLeft(value: string, padding: string | number) {
    // ...
}

let indentedString = padLeft("Hello world", true); // errors during compilation

Use the --strictNullChecks (:), optional parameters are automatically plus | undefined?:

function f(x: number, y?: number) {
    return x + (y || 0);
}
f(1, 2);
f(1);
f(1, undefined);
f(1, null); // error, 'null' is not assignable to 'number | undefined'
Published 170 original articles · won praise 59 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43972437/article/details/104085504