Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,27 @@ impl<'a> Visit<'a> for ExplicitTypesChecker<'a, '_> {

self.ctx.diagnostic(func_missing_argument_type(it.span));
}

fn visit_ts_as_expression(&mut self, it: &TSAsExpression<'a>) {
if is_wrapped_function_expression(&it.expression) {
return;
}
walk::walk_ts_as_expression(self, it);
}

fn visit_ts_satisfies_expression(&mut self, it: &TSSatisfiesExpression<'a>) {
if is_wrapped_function_expression(&it.expression) {
return;
}
walk::walk_ts_satisfies_expression(self, it);
}

fn visit_ts_type_assertion(&mut self, it: &TSTypeAssertion<'a>) {
if is_wrapped_function_expression(&it.expression) {
return;
}
walk::walk_ts_type_assertion(self, it);
}
}

/// like [`Expression::get_inner_expression`], but does not skip over most ts syntax
Expand All @@ -715,6 +736,13 @@ fn get_typed_inner_expression<'a, 'e>(expr: &'e Expression<'a>) -> &'e Expressio
}
}

fn is_wrapped_function_expression(expr: &Expression<'_>) -> bool {
matches!(
get_typed_inner_expression(expr),
Expression::ArrowFunctionExpression(_) | Expression::FunctionExpression(_)
)
}

#[cfg(test)]
mod test {
use super::{ExplicitModuleBoundaryTypes, ExplicitModuleBoundaryTypesConfig};
Expand Down Expand Up @@ -924,10 +952,6 @@ mod test {
"const x = (() => {}) as Foo;",
Some(json!([{ "allowTypedFunctionExpressions": true }])),
),
(
"type F = (x: number) => number; export const f = (x => x) satisfies F;",
None,
),
(
"
export const x = {
Expand Down Expand Up @@ -1562,6 +1586,30 @@ mod test {
",
None,
),
(
"type F = (x: number) => number; export const f = (x => x) satisfies F;",
None,
),
(
"
type F = () => number;

export const OBJ = {
f: (() => 42) satisfies F,
};
",
None,
),
(
"
type F = () => number;

export class Class {
g = (() => 42) satisfies F;
}
",
None,
),
];

let fail = vec![
Expand Down
Loading