From c735553316991802323c050b13874b37ed262d5e Mon Sep 17 00:00:00 2001 From: wxsm Date: Thu, 10 Feb 2022 09:39:23 +0800 Subject: [PATCH 1/2] add codestyle to some words --- src/guide/typescript/options-api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/guide/typescript/options-api.md b/src/guide/typescript/options-api.md index eacae4e2a9..9ff9ea9e5d 100644 --- a/src/guide/typescript/options-api.md +++ b/src/guide/typescript/options-api.md @@ -6,7 +6,7 @@ While Vue does support TypeScript usage with Options API, it is recommended to use Vue with TypeScript via Composition API as it offers simpler, more efficient and more robust type inference. ::: -## Typing Component Props +## Typing Component `props` Type inference for props in Options API requires wrapping the component with `defineComponent()`. With it, Vue is able to infer the types for the props based on the `props` option, taking additional options such as `required: true` and `default` into account: @@ -30,7 +30,7 @@ export default defineComponent({ }) ``` -However, the runtime props options only support using constructor functions as a prop's type - there is no way to specify complex types such as objects with nested properties or function call signatures. +However, the runtime `props` options only support using constructor functions as a prop's type - there is no way to specify complex types such as objects with nested properties or function call signatures. To annotate complex props types, we can use the `PropType` utility type: @@ -92,7 +92,7 @@ export default defineComponent({ This prevents TypeScript from having to infer the type of `this` inside these functions, which, unfortunately, can cause the type inference to fail. -## Typing Component Emits +## Typing Component `emits` We can declare the expected payload type for an emitted event using the object syntax of the `emits` option. Also, all non-declared emitted events will throw a type error when called: From 4f20c1717655efd9b59459bd0f10ab66178274ea Mon Sep 17 00:00:00 2001 From: wxsm Date: Fri, 11 Feb 2022 10:25:25 +0800 Subject: [PATCH 2/2] Update options-api.md --- src/guide/typescript/options-api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/guide/typescript/options-api.md b/src/guide/typescript/options-api.md index 9ff9ea9e5d..83363615a0 100644 --- a/src/guide/typescript/options-api.md +++ b/src/guide/typescript/options-api.md @@ -6,7 +6,7 @@ While Vue does support TypeScript usage with Options API, it is recommended to use Vue with TypeScript via Composition API as it offers simpler, more efficient and more robust type inference. ::: -## Typing Component `props` +## Typing Component Props Type inference for props in Options API requires wrapping the component with `defineComponent()`. With it, Vue is able to infer the types for the props based on the `props` option, taking additional options such as `required: true` and `default` into account: @@ -92,7 +92,7 @@ export default defineComponent({ This prevents TypeScript from having to infer the type of `this` inside these functions, which, unfortunately, can cause the type inference to fail. -## Typing Component `emits` +## Typing Component Emits We can declare the expected payload type for an emitted event using the object syntax of the `emits` option. Also, all non-declared emitted events will throw a type error when called: