Skip to content

Commit 40b3c35

Browse files
committed
feat: object literal completions for boolean types (a: true/false,)
1 parent fa6e025 commit 40b3c35

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

typescript/src/completions/objectLiteralCompletions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default (
5858
const insertObjectArrayInnerText = c('objectLiteralCompletions.insertNewLine') ? '\n\t$1\n' : '$1'
5959
const completingStyleMap = [
6060
[getQuotedSnippet, isStringCompletion],
61+
[[': ${1|true,false|},$0', `: true/false,`], isBooleanCompletion],
6162
[[`: [${insertObjectArrayInnerText}],$0`, `: [],`], isArrayCompletion],
6263
[[`: {${insertObjectArrayInnerText}},$0`, `: {},`], isObjectCompletion],
6364
] as const
@@ -107,6 +108,14 @@ const isStringCompletion = (type: ts.Type) => {
107108
return false
108109
}
109110

111+
const isBooleanCompletion = (type: ts.Type) => {
112+
if (type.flags & ts.TypeFlags.Undefined) return false
113+
// todo support boolean literals (boolean like)
114+
if (type.flags & ts.TypeFlags.Boolean) return true
115+
if (type.isUnion()) return isEverySubtype(type, type => isBooleanCompletion(type))
116+
return false
117+
}
118+
110119
const isArrayCompletion = (type: ts.Type, checker: ts.TypeChecker) => {
111120
if (type.flags & ts.TypeFlags.Any) return false
112121
if (type.flags & ts.TypeFlags.Undefined) return false

0 commit comments

Comments
 (0)