Skip to content
Open
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
4 changes: 4 additions & 0 deletions internal/checker/pseudotypenodebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod
return b.f.NewLiteralTypeNode(b.f.NewKeywordExpression(ast.KindFalseKeyword))
case pseudochecker.PseudoTypeKindTrue:
return b.f.NewLiteralTypeNode(b.f.NewKeywordExpression(ast.KindTrueKeyword))
case pseudochecker.PseudoTypeKindVoid:
return b.f.NewKeywordTypeNode(ast.KindVoidKeyword)
case pseudochecker.PseudoTypeKindSingleCallSignature:
d := t.AsPseudoTypeSingleCallSignature()
signature := b.ch.getSignatureFromDeclaration(d.Signature)
Expand Down Expand Up @@ -744,6 +746,8 @@ func (b *NodeBuilderImpl) pseudoTypeToType(t *pseudochecker.PseudoType) *Type {
return b.ch.falseType
case pseudochecker.PseudoTypeKindTrue:
return b.ch.trueType
case pseudochecker.PseudoTypeKindVoid:
return b.ch.voidType
case pseudochecker.PseudoTypeKindStringLiteral, pseudochecker.PseudoTypeKindNumericLiteral, pseudochecker.PseudoTypeKindBigIntLiteral:
source := t.AsPseudoTypeLiteral().Node
return b.ch.getRegularTypeOfExpression(source) // big shortcut, uses cached expression types where possible
Expand Down
4 changes: 4 additions & 0 deletions internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ TestCodeFixInferFromUsageRestParam3
TestCodeFixInferFromUsageVariable3JS
TestCodeFixMissingTypeAnnotationOnExports11
TestCodeFixMissingTypeAnnotationOnExports16
TestCodeFixMissingTypeAnnotationOnExports22_formatting
Comment on lines 64 to +66
TestCodeFixMissingTypeAnnotationOnExports23_heritage_formatting
TestCodeFixMissingTypeAnnotationOnExports24_heritage_formatting_2
TestCodeFixMissingTypeAnnotationOnExports25_heritage_formatting_3
TestCodeFixMissingTypeAnnotationOnExports28_long_types
TestCodeFixMissingTypeAnnotationOnExports33_methods
TestCodeFixMissingTypeAnnotationOnExports43_expando_functions_2
TestCodeFixMissingTypeAnnotationOnExports46_decorators_experimental
Comment on lines 70 to +73
TestCodeFixSpelling4
TestCodeFixSpelling5
TestCodeFixSpellingCaseSensitive1
Expand Down
3 changes: 3 additions & 0 deletions internal/pseudochecker/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ func (ch *PseudoChecker) typeFromSingleReturnExpression(fn *ast.Node) *PseudoTyp

body := fn.Body()
if ast.IsBlock(body) {
if len(body.Statements()) == 0 {
return PseudoTypeVoid
}
ast.ForEachReturnStatement(body, func(stmt *ast.Node) bool {
Comment on lines 227 to 232
if stmt.Parent != body { // Why bail on nested return statements?
candidateExpr = nil
Expand Down
2 changes: 2 additions & 0 deletions internal/pseudochecker/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
PseudoTypeKindBoolean
PseudoTypeKindFalse
PseudoTypeKindTrue
PseudoTypeKindVoid
PseudoTypeKindSingleCallSignature
PseudoTypeKindTuple
PseudoTypeKindObjectLiteral
Expand Down Expand Up @@ -77,6 +78,7 @@ var (
PseudoTypeBoolean = newPseudoType(PseudoTypeKindBoolean, &PseudoTypeBase{})
PseudoTypeFalse = newPseudoType(PseudoTypeKindFalse, &PseudoTypeBase{})
PseudoTypeTrue = newPseudoType(PseudoTypeKindTrue, &PseudoTypeBase{})
PseudoTypeVoid = newPseudoType(PseudoTypeKindVoid, &PseudoTypeBase{})
)

// PseudoTypeDirect directly encodes the type referred to by a given TypeNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ isolatedDeclarationErrors.ts(2,1): error TS9023: Assigning properties to functio
isolatedDeclarationErrors.ts(2,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrors.ts(5,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrors.ts(5,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrors.ts(7,30): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrors.ts(8,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrors.ts(8,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.


==== isolatedDeclarationErrors.ts (7 errors) ====
==== isolatedDeclarationErrors.ts (6 errors) ====
function errorOnAssignmentBelowDecl(): void {}
errorOnAssignmentBelowDecl.a = "";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -23,10 +22,6 @@ isolatedDeclarationErrors.ts(8,1): error TS9013: Expression type can't be inferr
!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations.

const errorOnMissingReturn = () => {}
~~~~~~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9027 isolatedDeclarationErrors.ts:7:7: Add a type annotation to the variable errorOnMissingReturn.
!!! related TS9030 isolatedDeclarationErrors.ts:7:30: Add a return type to the function expression.
errorOnMissingReturn.a = "";
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
isolatedDeclarationErrorsClasses.ts(3,5): error TS9012: Property must have an explicit type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(4,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(8,18): error TS7006: Parameter 'p' implicitly has an 'any' type.
isolatedDeclarationErrorsClasses.ts(8,18): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(9,23): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
Expand All @@ -11,7 +10,6 @@ isolatedDeclarationErrorsClasses.ts(36,5): error TS9038: Computed property names
isolatedDeclarationErrorsClasses.ts(36,6): error TS2304: Cannot find name 'missing'.
isolatedDeclarationErrorsClasses.ts(38,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(40,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(42,5): error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(42,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(44,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsClasses.ts(44,35): error TS7006: Parameter 'v' implicitly has an 'any' type.
Expand All @@ -26,17 +24,14 @@ isolatedDeclarationErrorsClasses.ts(56,5): error TS7010: '[noAnnotationLiteralNa
isolatedDeclarationErrorsClasses.ts(56,5): error TS9013: Expression type can't be inferred with --isolatedDeclarations.


==== isolatedDeclarationErrorsClasses.ts (26 errors) ====
==== isolatedDeclarationErrorsClasses.ts (24 errors) ====
export class Cls {

field = 1 + 1;
~~~~~
!!! error TS9012: Property must have an explicit type annotation with --isolatedDeclarations.
!!! related TS9029 isolatedDeclarationErrorsClasses.ts:3:5: Add a type annotation to the property field.
method() {}
~~~~~~
!!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9034 isolatedDeclarationErrorsClasses.ts:4:5: Add a return type to the method

methodOk(): void {}

Expand Down Expand Up @@ -103,9 +98,6 @@ isolatedDeclarationErrorsClasses.ts(56,5): error TS9013: Expression type can't b

[noAnnotationStringName]() { }
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS9008: Method must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9034 isolatedDeclarationErrorsClasses.ts:42:5: Add a return type to the method
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.

[noParamAnnotationStringName](v): void { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,46 @@
isolatedDeclarationErrorsExpandoFunctions.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(3,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrorsExpandoFunctions.ts(3,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(3,13): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(4,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrorsExpandoFunctions.ts(4,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(4,12): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(5,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrorsExpandoFunctions.ts(5,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(5,12): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(6,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrorsExpandoFunctions.ts(6,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(6,14): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(7,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrorsExpandoFunctions.ts(7,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(7,16): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(8,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
isolatedDeclarationErrorsExpandoFunctions.ts(8,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsExpandoFunctions.ts(9,1): error TS9013: Expression type can't be inferred with --isolatedDeclarations.


==== isolatedDeclarationErrorsExpandoFunctions.ts (19 errors) ====
==== isolatedDeclarationErrorsExpandoFunctions.ts (13 errors) ====
export function foo() {}
~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9031 isolatedDeclarationErrorsExpandoFunctions.ts:1:17: Add a return type to the function declaration.

foo.apply = () => {}
~~~~~~~~~
!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
~~~~~~~~~~~~~~~~~~~~
!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations.
~~~~~~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9030 isolatedDeclarationErrorsExpandoFunctions.ts:3:13: Add a return type to the function expression.
foo.call = ()=> {}
~~~~~~~~
!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
~~~~~~~~~~~~~~~~~~
!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations.
~~~~~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9030 isolatedDeclarationErrorsExpandoFunctions.ts:4:12: Add a return type to the function expression.
foo.bind = ()=> {}
~~~~~~~~
!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
~~~~~~~~~~~~~~~~~~
!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations.
~~~~~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9030 isolatedDeclarationErrorsExpandoFunctions.ts:5:12: Add a return type to the function expression.
foo.caller = ()=> {}
~~~~~~~~~~
!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
~~~~~~~~~~~~~~~~~~~~
!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations.
~~~~~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9030 isolatedDeclarationErrorsExpandoFunctions.ts:6:14: Add a return type to the function expression.
foo.toString = ()=> {}
~~~~~~~~~~~~
!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS9013: Expression type can't be inferred with --isolatedDeclarations.
~~~~~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9030 isolatedDeclarationErrorsExpandoFunctions.ts:7:16: Add a return type to the function expression.
foo.length = 10
~~~~~~~~~~
!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
isolatedDeclarationErrorsFunctionDeclarations.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(3,35): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(7,49): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(7,66): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(7,81): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(9,55): error TS9013: Expression type can't be inferred with --isolatedDeclarations.


==== isolatedDeclarationErrorsFunctionDeclarations.ts (6 errors) ====
==== isolatedDeclarationErrorsFunctionDeclarations.ts (5 errors) ====
export function noReturn() {}
~~~~~~~~
!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
!!! related TS9031 isolatedDeclarationErrorsFunctionDeclarations.ts:1:17: Add a return type to the function declaration.

export function noParamAnnotation(p): void {}
~
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- old.isolatedDeclarationErrorsFunctionDeclarations.errors.txt
+++ new.isolatedDeclarationErrorsFunctionDeclarations.errors.txt
@@= skipped -0, +0 lines =@@
-isolatedDeclarationErrorsFunctionDeclarations.ts(1,17): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(3,35): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(7,49): error TS9011: Parameter must have an explicit type annotation with --isolatedDeclarations.
isolatedDeclarationErrorsFunctionDeclarations.ts(7,66): error TS9013: Expression type can't be inferred with --isolatedDeclarations.
@@= skipped -5, +4 lines =@@
isolatedDeclarationErrorsFunctionDeclarations.ts(9,55): error TS9013: Expression type can't be inferred with --isolatedDeclarations.


-==== isolatedDeclarationErrorsFunctionDeclarations.ts (6 errors) ====
+==== isolatedDeclarationErrorsFunctionDeclarations.ts (5 errors) ====
export function noReturn() {}
- ~~~~~~~~
-!!! error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.
-!!! related TS9031 isolatedDeclarationErrorsFunctionDeclarations.ts:1:17: Add a return type to the function declaration.

export function noParamAnnotation(p): void {}
~
Loading