File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -87,12 +87,22 @@ function isTypedParent(
87
87
return (
88
88
isTypeAssertion ( parent ) ||
89
89
isVariableDeclaratorWithTypeAnnotation ( parent ) ||
90
+ isDefaultFunctionParameterWithTypeAnnotation ( parent ) ||
90
91
isPropertyDefinitionWithTypeAnnotation ( parent ) ||
91
92
isFunctionArgument ( parent , callee ) ||
92
93
isTypedJSX ( parent )
93
94
) ;
94
95
}
95
96
97
+ function isDefaultFunctionParameterWithTypeAnnotation (
98
+ node : TSESTree . Node ,
99
+ ) : boolean {
100
+ return (
101
+ node . type === AST_NODE_TYPES . AssignmentPattern &&
102
+ node . left . typeAnnotation != null
103
+ ) ;
104
+ }
105
+
96
106
/**
97
107
* Checks if a node belongs to:
98
108
* ```
Original file line number Diff line number Diff line change @@ -770,6 +770,22 @@ class Bar {
770
770
}
771
771
` ,
772
772
} ,
773
+ {
774
+ code : `
775
+ type CallBack = () => void;
776
+
777
+ function f(gotcha: CallBack = () => {}): void {}
778
+ ` ,
779
+ options : [ { allowTypedFunctionExpressions : true } ] ,
780
+ } ,
781
+ {
782
+ code : `
783
+ type CallBack = () => void;
784
+
785
+ const f = (gotcha: CallBack = () => {}): void => {};
786
+ ` ,
787
+ options : [ { allowTypedFunctionExpressions : true } ] ,
788
+ } ,
773
789
] ,
774
790
invalid : [
775
791
{
@@ -1940,5 +1956,39 @@ let foo = (() => () => {})()();
1940
1956
} ,
1941
1957
] ,
1942
1958
} ,
1959
+ {
1960
+ code : `
1961
+ type CallBack = () => void;
1962
+
1963
+ function f(gotcha: CallBack = () => {}): void {}
1964
+ ` ,
1965
+ options : [ { allowTypedFunctionExpressions : false } ] ,
1966
+ errors : [
1967
+ {
1968
+ messageId : 'missingReturnType' ,
1969
+ line : 4 ,
1970
+ column : 34 ,
1971
+ endLine : 4 ,
1972
+ endColumn : 36 ,
1973
+ } ,
1974
+ ] ,
1975
+ } ,
1976
+ {
1977
+ code : `
1978
+ type CallBack = () => void;
1979
+
1980
+ const f = (gotcha: CallBack = () => {}): void => {};
1981
+ ` ,
1982
+ options : [ { allowTypedFunctionExpressions : false } ] ,
1983
+ errors : [
1984
+ {
1985
+ messageId : 'missingReturnType' ,
1986
+ line : 4 ,
1987
+ column : 34 ,
1988
+ endLine : 4 ,
1989
+ endColumn : 36 ,
1990
+ } ,
1991
+ ] ,
1992
+ } ,
1943
1993
] ,
1944
1994
} ) ;
You can’t perform that action at this time.
0 commit comments