Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6987,7 +6987,7 @@ func (c *Checker) getQuickTypeOfExpression(node *ast.Node) *Type {

func (c *Checker) getReturnTypeOfSingleNonGenericCallSignature(funcType *Type) *Type {
signature := c.getSingleCallSignature(funcType)
if signature != nil && signature.typeParameters == nil {
if signature != nil && len(signature.typeParameters) == 0 {
return c.getReturnTypeOfSignature(signature)
}
return nil
Expand Down Expand Up @@ -9121,7 +9121,7 @@ func (c *Checker) inferTypeArguments(node *ast.Node, signature *Signature, args
// Above, the type of the 'value' parameter is inferred to be 'A'.
contextualSignature := c.getSingleCallSignature(instantiatedType)
var inferenceSourceType *Type
if contextualSignature != nil && contextualSignature.typeParameters != nil {
if contextualSignature != nil && len(contextualSignature.typeParameters) != 0 {
inferenceSourceType = c.getOrCreateTypeFromSignature(c.getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters), nil)
} else {
inferenceSourceType = instantiatedType
Expand Down Expand Up @@ -9382,7 +9382,7 @@ func (c *Checker) addImplementationSuccessElaboration(s *CallState, failed *Sign
candidate := c.getSignatureFromDeclaration(implementation)
localState := *s
localState.candidates = []*Signature{candidate}
localState.isSingleNonGenericCandidate = candidate.typeParameters == nil
localState.isSingleNonGenericCandidate = len(candidate.typeParameters) == 0
if c.chooseOverload(&localState, c.assignableRelation) != nil {
diagnostic.AddRelatedInfo(NewDiagnosticForNode(implementation, diagnostics.The_call_would_have_succeeded_against_this_implementation_but_implementation_signatures_of_overloads_are_not_externally_visible))
}
Expand Down Expand Up @@ -9949,8 +9949,8 @@ func (c *Checker) isAritySmaller(signature *Signature, target *ast.Node) bool {
}

func (c *Checker) assignContextualParameterTypes(sig *Signature, context *Signature) {
if context.typeParameters != nil {
if sig.typeParameters != nil {
if len(context.typeParameters) != 0 {
if len(sig.typeParameters) != 0 {
// This signature has already has a contextual inference performed and cached on it
return
}
Expand Down Expand Up @@ -20201,8 +20201,8 @@ func (c *Checker) getUnionSignatures(signatureLists [][]*Signature) []*Signature
if !core.Same(signatures, masterList) {
signature := signatures[0]
// Debug.assert(signature, "getUnionSignatures bails early on empty signature lists and should not have empty lists on second pass")
if signature.typeParameters != nil && core.Some(results, func(s *Signature) bool {
return s.typeParameters != nil && !c.compareTypeParametersIdentical(signature.typeParameters, s.typeParameters)
if len(signature.typeParameters) != 0 && core.Some(results, func(s *Signature) bool {
return len(s.typeParameters) != 0 && !c.compareTypeParametersIdentical(signature.typeParameters, s.typeParameters)
}) {
results = nil
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ func (c *Checker) getEffectsSignature(node *ast.Node) *Signature {
}
signatures := c.getSignaturesOfType(core.OrElse(apparentType, c.unknownType), SignatureKindCall)
switch {
case len(signatures) == 1 && signatures[0].typeParameters == nil:
case len(signatures) == 1 && len(signatures[0].typeParameters) == 0:
signature = signatures[0]
case core.Some(signatures, c.hasTypePredicateOrNeverReturnType):
signature = c.getResolvedSignature(node, nil, CheckModeNormal)
Expand Down
4 changes: 2 additions & 2 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1690,11 +1690,11 @@ func (b *nodeBuilderImpl) signatureToSignatureDeclarationHelper(signature *Signa
b.ctx.approximateLength += 3
// Usually a signature contributes a few more characters than this, but 3 is the minimum

if b.ctx.flags&nodebuilder.FlagsWriteTypeArgumentsOfSignature != 0 && signature.target != nil && signature.mapper != nil && signature.target.typeParameters != nil {
if b.ctx.flags&nodebuilder.FlagsWriteTypeArgumentsOfSignature != 0 && signature.target != nil && signature.mapper != nil && len(signature.target.typeParameters) != 0 {
for _, parameter := range signature.target.typeParameters {
typeParameters = append(typeParameters, b.typeToTypeNode(b.ch.instantiateType(parameter, signature.mapper)))
}
} else if signature.typeParameters != nil {
} else {
for _, parameter := range signature.typeParameters {
typeParameters = append(typeParameters, b.typeParameterToDeclaration(parameter))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/checker/relater.go
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ func (c *Checker) compareSignaturesRelated(source *Signature, target *Signature,
}
return TernaryFalse
}
if source.typeParameters != nil && !core.Same(source.typeParameters, target.typeParameters) {
if len(source.typeParameters) != 0 && !core.Same(source.typeParameters, target.typeParameters) {
target = c.getCanonicalSignature(target)
source = c.instantiateSignatureInContextOf(source, target /*inferenceContext*/, nil, compareTypes)
}
Expand Down Expand Up @@ -1653,7 +1653,7 @@ func (c *Checker) compareTypePredicateRelatedTo(source *TypePredicate, target *T

// Returns true if `s` is `(...args: A) => R` where `A` is `any`, `any[]`, `never`, or `never[]`, and `R` is `any` or `unknown`.
func (c *Checker) isTopSignature(s *Signature) bool {
if s.typeParameters == nil && (s.thisParameter == nil || IsTypeAny(c.getTypeOfParameter(s.thisParameter))) && len(s.parameters) == 1 && signatureHasRestParameter(s) {
if len(s.typeParameters) == 0 && (s.thisParameter == nil || IsTypeAny(c.getTypeOfParameter(s.thisParameter))) && len(s.parameters) == 1 && signatureHasRestParameter(s) {
paramType := c.getTypeOfParameter(s.parameters[0])
var restType *Type
if c.isArrayType(paramType) {
Expand Down Expand Up @@ -2090,7 +2090,7 @@ func (c *Checker) isResolvingReturnTypeOfSignature(signature *Signature) bool {
}

func (c *Checker) findMatchingSignatures(signatureLists [][]*Signature, signature *Signature, listIndex int) []*Signature {
if signature.typeParameters != nil {
if len(signature.typeParameters) != 0 {
// We require an exact match for generic signatures, so we only return signatures from the first
// signature list and only if they have exact matches in the other signature lists.
if listIndex > 0 {
Expand Down Expand Up @@ -2150,7 +2150,7 @@ func (c *Checker) compareSignaturesIdentical(source *Signature, target *Signatur
}
// Check that type parameter constraints and defaults match. If they do, instantiate the source
// signature with the type parameters of the target signature and continue the comparison.
if target.typeParameters != nil {
if len(target.typeParameters) != 0 {
mapper := newTypeMapper(source.typeParameters, target.typeParameters)
for i := range len(target.typeParameters) {
s := source.typeParameters[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ new cls2(); // should error
>cls2 : Abstracts

new cls3(); // should work
>new cls3() : ConcreteA
>new cls3() : ConcreteA | ConcreteB
>cls3 : Concretes

[ConcreteA, AbstractA, AbstractB].map(cls => new cls()); // should error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
--- old.abstractClassUnionInstantiation.types
+++ new.abstractClassUnionInstantiation.types
@@= skipped -45, +45 lines =@@
>cls2 : Abstracts

new cls3(); // should work
->new cls3() : ConcreteA | ConcreteB
+>new cls3() : ConcreteA
>cls3 : Concretes

[ConcreteA, AbstractA, AbstractB].map(cls => new cls()); // should error
@@= skipped -31, +31 lines =@@
@@= skipped -76, +76 lines =@@

[ConcreteA, ConcreteB].map(cls => new cls()); // should work
>[ConcreteA, ConcreteB].map(cls => new cls()) : ConcreteA[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ jsxComponentTypeErrors.tsx(27,16): error TS2786: 'ClassComponent' cannot be used
Its instance type 'ClassComponent' is not a valid JSX element.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"element-class"'.
jsxComponentTypeErrors.tsx(28,16): error TS2604: JSX element type 'MixedComponent' does not have any construct or call signatures.
jsxComponentTypeErrors.tsx(28,16): error TS2786: 'MixedComponent' cannot be used as a JSX component.
Its element type 'ClassComponent | { type: string | undefined; }' is not a valid JSX element.
Type 'ClassComponent' is not assignable to type 'Element | ElementClass | null'.
Type 'ClassComponent' is not assignable to type 'Element | ElementClass'.
Type 'ClassComponent' is not assignable to type 'ElementClass'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"element-class"'.
jsxComponentTypeErrors.tsx(37,16): error TS2786: 'obj.MemberFunctionComponent' cannot be used as a JSX component.
Property 'type' is missing in type '{}' but required in type 'Element'.
jsxComponentTypeErrors.tsx(38,16): error TS2786: 'obj. MemberClassComponent' cannot be used as a JSX component.
Expand Down Expand Up @@ -77,7 +83,13 @@ jsxComponentTypeErrors.tsx(38,16): error TS2786: 'obj. MemberClassComponent' can
!!! error TS2786: Type 'string' is not assignable to type '"element-class"'.
const elem4 = <MixedComponent />;
~~~~~~~~~~~~~~
!!! error TS2604: JSX element type 'MixedComponent' does not have any construct or call signatures.
!!! error TS2786: 'MixedComponent' cannot be used as a JSX component.
!!! error TS2786: Its element type 'ClassComponent | { type: string | undefined; }' is not a valid JSX element.
!!! error TS2786: Type 'ClassComponent' is not assignable to type 'Element | ElementClass | null'.
!!! error TS2786: Type 'ClassComponent' is not assignable to type 'Element | ElementClass'.
!!! error TS2786: Type 'ClassComponent' is not assignable to type 'ElementClass'.
!!! error TS2786: Types of property 'type' are incompatible.
!!! error TS2786: Type 'string' is not assignable to type '"element-class"'.

const obj = {
MemberFunctionComponent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
--- old.jsxComponentTypeErrors.errors.txt
+++ new.jsxComponentTypeErrors.errors.txt
@@= skipped -16, +16 lines =@@
Its instance type 'ClassComponent' is not a valid JSX element.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"element-class"'.
-jsxComponentTypeErrors.tsx(28,16): error TS2786: 'MixedComponent' cannot be used as a JSX component.
- Its element type 'ClassComponent | { type: string | undefined; }' is not a valid JSX element.
- Type 'ClassComponent' is not assignable to type 'Element | ElementClass | null'.
- Type 'ClassComponent' is not assignable to type 'Element | ElementClass'.
- Type 'ClassComponent' is not assignable to type 'ElementClass'.
- Types of property 'type' are incompatible.
- Type 'string' is not assignable to type '"element-class"'.
+jsxComponentTypeErrors.tsx(28,16): error TS2604: JSX element type 'MixedComponent' does not have any construct or call signatures.
@@= skipped -24, +24 lines =@@
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"element-class"'.
jsxComponentTypeErrors.tsx(37,16): error TS2786: 'obj.MemberFunctionComponent' cannot be used as a JSX component.
- Its return type '{}' is not a valid JSX element.
- Property 'type' is missing in type '{}' but required in type 'Element'.
Expand All @@ -23,22 +14,7 @@


==== jsxComponentTypeErrors.tsx (7 errors) ====
@@= skipped -68, +60 lines =@@
!!! error TS2786: Type 'string' is not assignable to type '"element-class"'.
const elem4 = <MixedComponent />;
~~~~~~~~~~~~~~
-!!! error TS2786: 'MixedComponent' cannot be used as a JSX component.
-!!! error TS2786: Its element type 'ClassComponent | { type: string | undefined; }' is not a valid JSX element.
-!!! error TS2786: Type 'ClassComponent' is not assignable to type 'Element | ElementClass | null'.
-!!! error TS2786: Type 'ClassComponent' is not assignable to type 'Element | ElementClass'.
-!!! error TS2786: Type 'ClassComponent' is not assignable to type 'ElementClass'.
-!!! error TS2786: Types of property 'type' are incompatible.
-!!! error TS2786: Type 'string' is not assignable to type '"element-class"'.
+!!! error TS2604: JSX element type 'MixedComponent' does not have any construct or call signatures.

const obj = {
MemberFunctionComponent() {
@@= skipped -18, +12 lines =@@
@@= skipped -78, +76 lines =@@
const elem5 = <obj.MemberFunctionComponent />;
~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2786: 'obj.MemberFunctionComponent' cannot be used as a JSX component.
Expand Down
Loading