// vue
declare type ASTElementHandler = {
value: string;
params?: Array<any>;
modifiers: ?ASTModifiers;// undefinednull
};
// vue
declare type ASTElementHandler = {
value: string;
params?: Array<any>;
modifiers: ?ASTModifiers;// undefinednull
};
4.declare type is because js itself is a weakly typed language, and it is inefficient to determine whether there is something wrong with the type or to do some operation at run time.
after the type is declared in advance, on the one hand, it is easier to cooperate and more standardized. On the other hand, syntax errors can be detected during the compilation phase. Save running time.
I would like to add one more point:
optional types (Maybe Types)
optional types are used where the value is optional, and the usage is to precede the type with a?, such as? string or? number. The optional type can be null or void.
// @flow
function acceptsMaybeString(value: ?string) {
// ...
}
acceptsMaybeString("bar"); // Works!
acceptsMaybeString(undefined); // Works!
acceptsMaybeString(null); // Works!
acceptsMaybeString(); // Works!
?voidnull:
// @flow
function acceptsObject(value: { foo?: string }) {
// ...
}
acceptsObject({ foo: "bar" }); // Works!
acceptsObject({ foo: undefined }); // Works!
acceptsObject({ foo: null }); // Error!
acceptsObject({}); // Works!
optional function parameters
the use of a function with optional parameters is to add a? after the parameter, which can be void or omitted, but cannot be null. For example,
// @flow
function acceptsOptionalString(value?: string) {
// ...
}
acceptsOptionalString("bar"); // Works!
acceptsOptionalString(undefined); // Works!
acceptsOptionalString(null); // Error!
acceptsOptionalString(); // Works!
Previous: When writing a typescript plug-in, you can get the compiled code or objects of ast when you visitor.
Next: Why do subcomponents not need import vue? when using vue