Skip to content

Commit a9a9d58

Browse files
authored
Move ID error for accessor inference failure from return expression to (both) accessors (#4517)
1 parent d472c39 commit a9a9d58

7 files changed

Lines changed: 17 additions & 52 deletions

File tree

internal/fourslash/_scripts/manualTests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ autoImportPackageRootPathExtension
88
autoImportPackageRootPathTypeModule
99
autoImportProvider5
1010
autoImportSymlinkCaseSensitive
11+
codeFixMissingTypeAnnotationOnExports45-decorators
12+
codeFixMissingTypeAnnotationOnExports46-decorators-experimental
1113
completionForStringLiteral_details
1214
completionForStringLiteralExport
1315
completionForStringLiteralImport1

internal/fourslash/tests/gen/codeFixMissingTypeAnnotationOnExports45-decorators_test.go renamed to internal/fourslash/tests/manual/codeFixMissingTypeAnnotationOnExports45-decorators_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Code generated by convertFourslash; DO NOT EDIT.
2-
// To modify this test, run "npm run makemanual codeFixMissingTypeAnnotationOnExports45-decorators"
3-
41
package fourslash_test
52

63
import (
@@ -11,7 +8,6 @@ import (
118
)
129

1310
func TestCodeFixMissingTypeAnnotationOnExports45_decorators(t *testing.T) {
14-
fourslash.SkipIfFailing(t)
1511
t.Parallel()
1612
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1713
const content = `// @isolatedDeclarations: true
@@ -71,7 +67,7 @@ export class A {
7167
return foo();
7268
}
7369
@setterDecorator
74-
set a(value) {}
70+
set a(value: number) {}
7571
7672
@fieldDecorator classProp: number = foo();
7773
}`,

internal/fourslash/tests/gen/codeFixMissingTypeAnnotationOnExports46-decorators-experimental_test.go renamed to internal/fourslash/tests/manual/codeFixMissingTypeAnnotationOnExports46-decorators-experimental_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Code generated by convertFourslash; DO NOT EDIT.
2-
// To modify this test, run "npm run makemanual codeFixMissingTypeAnnotationOnExports46-decorators-experimental"
3-
41
package fourslash_test
52

63
import (
@@ -11,7 +8,6 @@ import (
118
)
129

1310
func TestCodeFixMissingTypeAnnotationOnExports46_decorators_experimental(t *testing.T) {
14-
fourslash.SkipIfFailing(t)
1511
t.Parallel()
1612
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1713
const content = `// @isolatedDeclarations: true
@@ -71,7 +67,7 @@ export class A {
7167
return foo();
7268
}
7369
@setterDecorator()
74-
set a(value) {}
70+
set a(value: number) {}
7571
@fieldDecorator() classProp: number = foo();
7672
}`,
7773
})

internal/pseudochecker/lookup.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ func (ch *PseudoChecker) GetReturnTypeOfSignature(signatureNode *ast.Node) *Pseu
2424
}
2525

2626
func (ch *PseudoChecker) GetTypeOfAccessor(accessor *ast.Node) *PseudoType {
27-
annotated := ch.typeFromAccessor(accessor)
28-
if annotated.Kind == PseudoTypeKindNoResult {
29-
return ch.inferAccessorType(accessor)
30-
}
31-
return annotated
27+
return ch.typeFromAccessor(accessor)
3228
}
3329

3430
func (ch *PseudoChecker) GetTypeOfExpression(node *ast.Node) *PseudoType {
@@ -154,18 +150,19 @@ func (ch *PseudoChecker) typeFromAccessor(accessor *ast.Node) *PseudoType {
154150
return NewPseudoTypeDirect(accessorType)
155151
}
156152
if accessorDeclarations.GetAccessor != nil {
157-
return ch.createReturnFromSignature(accessorDeclarations.GetAccessor.AsNode())
153+
res := ch.createReturnFromSignature(accessorDeclarations.GetAccessor.AsNode())
154+
if res.Kind == PseudoTypeKindInferred && len(res.AsPseudoTypeInferred().ErrorNodes) == 0 {
155+
errorNodes := []*ast.Node{accessorDeclarations.GetAccessor.AsNode()}
156+
if accessorDeclarations.SetAccessor != nil {
157+
errorNodes = append(errorNodes, accessorDeclarations.SetAccessor.AsNode())
158+
}
159+
res = NewPseudoTypeInferredWithErrors(res.AsPseudoTypeInferred().Expression, res.AsPseudoTypeInferred().IsSignatureReturn, errorNodes) // Move error up to the accessor
160+
}
161+
return res
158162
}
159163
return NewPseudoTypeNoResult(accessor)
160164
}
161165

162-
func (ch *PseudoChecker) inferAccessorType(node *ast.Node) *PseudoType {
163-
if node.Kind == ast.KindGetAccessor {
164-
return ch.createReturnFromSignature(node)
165-
}
166-
return NewPseudoTypeNoResult(node)
167-
}
168-
169166
func (ch *PseudoChecker) getTypeAnnotationFromAllAccessorDeclarations(node *ast.Node, accessors ast.AllAccessorDeclarations) *ast.Node {
170167
accessorType := ch.getTypeAnnotationFromAccessor(node)
171168
if accessorType == nil && node != accessors.FirstAccessor {

testdata/baselines/reference/submodule/compiler/isolatedDeclarationErrorsClasses.errors.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ isolatedDeclarationErrorsClasses.ts(4,5): error TS9008: Method must have an expl
33
isolatedDeclarationErrorsClasses.ts(8,18): error TS7006: Parameter 'p' implicitly has an 'any' type.
44
isolatedDeclarationErrorsClasses.ts(8,18): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
55
isolatedDeclarationErrorsClasses.ts(9,23): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
6-
isolatedDeclarationErrorsClasses.ts(11,28): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
6+
isolatedDeclarationErrorsClasses.ts(11,9): error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations.
77
isolatedDeclarationErrorsClasses.ts(12,9): error TS7032: Property 'setOnly' implicitly has type 'any', because its set accessor lacks a parameter type annotation.
88
isolatedDeclarationErrorsClasses.ts(12,17): error TS7006: Parameter 'value' implicitly has an 'any' type.
99
isolatedDeclarationErrorsClasses.ts(12,17): error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations.
@@ -52,10 +52,9 @@ isolatedDeclarationErrorsClasses.ts(56,5): error TS9013: Expression type can't b
5252
!!! related TS9028 isolatedDeclarationErrorsClasses.ts:9:19: Add a type annotation to the parameter p.
5353

5454
get getOnly() { return 1 + 1 }
55-
~~~~~
56-
!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations.
55+
~~~~~~~
56+
!!! error TS9009: At least one accessor must have an explicit type annotation with --isolatedDeclarations.
5757
!!! related TS9032 isolatedDeclarationErrorsClasses.ts:11:9: Add a return type to the get accessor declaration.
58-
!!! related TS9035 isolatedDeclarationErrorsClasses.ts:11:28: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit.
5958
set setOnly(value) { }
6059
~~~~~~~
6160
!!! error TS7032: Property 'setOnly' implicitly has type 'any', because its set accessor lacks a parameter type annotation.

testdata/baselines/reference/submoduleTriaged/compiler/isolatedDeclarationErrorsClasses.errors.txt.diff

Lines changed: 0 additions & 24 deletions
This file was deleted.

testdata/submoduleTriaged.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
# Omnibus: Isolated declarations error changes - needs investigation
66
## https://github.com/microsoft/typescript-go/issues/3477
7-
compiler/isolatedDeclarationErrorsClasses.errors.txt.diff
87
compiler/isolatedDeclarationErrorsClassesExpressions.errors.txt.diff
98
compiler/isolatedDeclarationsAddUndefined.errors.txt.diff
109

0 commit comments

Comments
 (0)