File tree Expand file tree Collapse file tree 3 files changed +268
-118
lines changed
inspect-extension/components/composition
packages/language-core/src Expand file tree Collapse file tree 3 files changed +268
-118
lines changed Original file line number Diff line number Diff line change 1
1
<template>
2
- <view class="list">
3
- <view wx:if="{{ shouldShow > 100}}">
4
- Case1: {{ shouldShow }}
2
+ <view>
3
+ <!-- Case1: Type Narrowing 类型收窄 -->
4
+ <view wx:if="{{ typeof msg === 'string'}}">
5
+ msg should be string: {{ msg }}
5
6
</view>
6
- <view wx:elif="{{ shouldShow > 10 }}">
7
- Case2 : {{ shouldShow }}
7
+ <view wx:elif="{{ typeof msg === 'number' }}">
8
+ msg should be number : {{ msg }}
8
9
</view>
9
10
<view wx:else>
10
- Case3 : {{ shouldShow }}
11
+ msg should be undefined : {{ msg }}
11
12
</view>
13
+
14
+ <!-- Case2: Type Narrowing for undefined -->
15
+ <view wx:if="{{ status }}">
16
+ {{ status.message }}
17
+ </view>
18
+
19
+ <!-- Case3: Type Narrowing -->
20
+ <view wx:if="{{ typeof foo === 'string' }}">
21
+ {{ foo }}
22
+ </view>
23
+
24
+ <!-- Case4: 表达式带空格 -->
25
+ <view wx:if=" {{ status?.message && msg }}"></view>
12
26
</view>
13
27
</template>
14
28
15
29
<script setup lang="ts">
16
30
import { ref } from "@mpxjs/core"
17
- const shouldShow = ref(0)
31
+
32
+ let msg = ref<string | number>()
33
+ let status: { message: string } | undefined;
34
+ let foo: any
18
35
19
36
defineExpose({
20
- shouldShow,
37
+ msg,
38
+ status,
39
+ foo
21
40
})
22
41
</script>
23
-
24
- <style lang="stylus">
25
- .list
26
- background-color red
27
- </style>
Original file line number Diff line number Diff line change @@ -215,4 +215,8 @@ declare module '@vue/compiler-dom' {
215
215
defaultValue ?: boolean
216
216
defaultIndex ?: boolean
217
217
}
218
+
219
+ export interface IfBranchNode {
220
+ mpxCondition ?: 'if' | 'elif' | 'else'
221
+ }
218
222
}
You can’t perform that action at this time.
0 commit comments