Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept baseline, fix lint
  • Loading branch information
rbuckton committed Jul 17, 2023
commit 6a4f838e705bf0cffde30e62bf93f570f8398353
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36541,7 +36541,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
if (hasInstanceMethodType) {
// avoid a complex check for every `instanceof` when the `[Symbol.hasInstance]` method has a single
// call signature that neither restricts nor narrows (via type predicate) the LHS value, e.g.
// call signature that neither restricts nor narrows (via type predicate) the LHS value, e.g.
// `(value: unknown) => boolean`.
const cache = hasInstanceMethodType as HasInstanceMethodType;
if (cache.hasSimpleUnrestrictedSingleCallSignature === undefined) {
Expand All @@ -36558,7 +36558,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// parameter.
const syntheticCall = createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType);
const returnType = getReturnTypeOfSignature(getResolvedSignature(syntheticCall));

// We also verify that the return type of the `[Symbol.hasInstance]` method is assignable to
// `boolean`. According to the spec, the runtime will actually perform `ToBoolean` on the result,
// but this is more type-safe.
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/symbolType1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
symbolType1.ts(1,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
symbolType1.ts(2,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
symbolType1.ts(4,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
symbolType1.ts(2,19): error TS2857: The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type.
symbolType1.ts(4,19): error TS2857: The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type.


==== symbolType1.ts (3 errors) ====
Expand All @@ -9,8 +9,8 @@ symbolType1.ts(4,19): error TS2359: The right-hand side of an 'instanceof' expre
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
Symbol instanceof Symbol();
~~~~~~~~
!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
!!! error TS2857: The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type.
(Symbol() || {}) instanceof Object; // This one should be okay, it's a valid way of distinguishing types
Symbol instanceof (Symbol() || {});
~~~~~~~~~~~~~~~~
!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
!!! error TS2857: The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type.