Skip to content

Commit f626dac

Browse files
committed
fix(objectLiteralCompletions): exclude object completions, where class or RegExp is expected
1 parent 118067e commit f626dac

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

typescript/src/completions/objectLiteralCompletions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default (
1919
const typeChecker = languageService.getProgram()!.getTypeChecker()!
2020
const objType = typeChecker.getContextualType(node)
2121
if (!objType) return
22+
// its doesn't return all actual properties in some cases e.g. it would be more correct to use symbols from entries, but there is a block from TS
2223
const properties = objType.getProperties()
2324
for (const property of properties) {
2425
const entry = entries.find(({ name }) => name === property.name)
@@ -100,7 +101,12 @@ const isArrayCompletion = (type: ts.Type, checker: ts.TypeChecker) => {
100101

101102
const isObjectCompletion = (type: ts.Type) => {
102103
if (type.flags & ts.TypeFlags.Undefined) return true
103-
if (type.flags & ts.TypeFlags.Object) return true
104+
if (type.flags & ts.TypeFlags.Object) {
105+
if ((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Class) return false
106+
// complete with regexp?
107+
if (type.symbol?.escapedName === 'RegExp') return false
108+
return true
109+
}
104110
if (type.isUnion()) return type.types.every(type => isObjectCompletion(type))
105111
return false
106112
}

0 commit comments

Comments
 (0)