Skip to content

Commit

Permalink
3.3: remove syntax limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
yutaroadachi committed May 20, 2023
1 parent 2ddaa6f commit ba0f36e
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/guide/typescript/composition-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,9 @@ const props = defineProps<Props>()

#### 構文の制限 {#syntax-limitations}

正しい実行時のコードが生成されるために、 `defineProps` の型引数は以下のいずれでなければなりません:
バージョン 3.2 以下では、`defineProps()` のジェネリック型の引数はリテラル型かローカルのインターフェースへの参照に制限されていました。

- オブジェクトリテラル型:

```ts
defineProps<{ /*... */ }>()
```

- **同じファイル内の** インターフェース、またはオブジェクトリテラル型への参照:

```ts
interface Props {/* ... */}

defineProps<Props>()
```

インターフェースやオブジェクトリテラル型自体は、他のファイルから import した型を含むことができますが、`defineProps()` の型引数に渡す引数は **他のファイルから import された型であってはいけません**:

```ts
import { Props } from './other-file'

// サポートされていない
defineProps<Props>()
```

これは、Vue コンポーネントが単独でコンパイルされるためで、コンパイラーはソースコードの型を分析するために import されたファイルをクロールすることがありません。この制限は将来のリリースで削除される可能性があります。
この制限は 3.3 で解決されました。Vue の最新バージョンは型引数の位置でインポートされた複雑な型の限定されたセットを参照することをサポートしています。しかし、型からランタイムへの変換は依然として AST ベースであるため、実際の型解析を必要とするいくつかの複雑な型、例えば条件型など、はサポートされていません。条件型は単一の prop の型には使用できますが、props オブジェクト全体の型には使用できません。

### プロパティのデフォルト値 {#props-default-values}

Expand Down

0 comments on commit ba0f36e

Please sign in to comment.