Skip to content

Commit 2962f47

Browse files
authored
Fix Caveats about props in TS with Options API
The inference limit of TypeScript has been improved in TypeScript 4.7. MR: microsoft/TypeScript#48538
1 parent f10655a commit 2962f47

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/guide/typescript/options-api.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default defineComponent({
6767

6868
### Caveats
6969

70-
Because of a [design limitation](https://github.com/microsoft/TypeScript/issues/38845) in TypeScript, you have to be careful when using function values for `validator` and `default` prop options - make sure to use arrow functions:
70+
If your TypeScript version is less than `4.7`, you have to be careful when using function values for `validator` and `default` prop options - make sure to use arrow functions:
7171

7272
```ts
7373
import { defineComponent } from 'vue'
@@ -82,7 +82,7 @@ export default defineComponent({
8282
props: {
8383
bookA: {
8484
type: Object as PropType<Book>,
85-
// Make sure to use arrow functions
85+
// Make sure to use arrow functions if your TypeScript version is less than 4.7
8686
default: () => ({
8787
title: 'Arrow Function Expression'
8888
}),
@@ -92,7 +92,7 @@ export default defineComponent({
9292
})
9393
```
9494

95-
This prevents TypeScript from having to infer the type of `this` inside these functions, which, unfortunately, can cause the type inference to fail.
95+
This prevents TypeScript from having to infer the type of `this` inside these functions, which, unfortunately, can cause the type inference to fail. It was a previous [design limitation](https://github.com/microsoft/TypeScript/issues/38845), and now has been improved in [TypeScript 4.7](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#improved-function-inference-in-objects-and-methods).
9696

9797
## Typing Component Emits
9898

0 commit comments

Comments
 (0)