fix(isolated-declarations): false positive for function with a type asserted parameters (#6181)

close: #6179
This commit is contained in:
Dunqing 2024-10-01 07:57:48 +00:00
parent 900cb46f6c
commit e9eeae0f4a
3 changed files with 5 additions and 10 deletions

View file

@ -3,12 +3,10 @@ use oxc_ast::ast::{
ArrowFunctionExpression, BindingPatternKind, Expression, FormalParameter, Function, Statement,
TSType, TSTypeAnnotation, UnaryExpression,
};
use oxc_span::{GetSpan, SPAN};
use oxc_span::SPAN;
use crate::{
diagnostics::{
array_inferred, inferred_type_of_class_expression, parameter_must_have_explicit_type,
},
diagnostics::{array_inferred, inferred_type_of_class_expression},
return_type::FunctionReturnType,
IsolatedDeclarations,
};
@ -101,12 +99,6 @@ impl<'a> IsolatedDeclarations<'a> {
// SAFETY: `ast.copy` is unsound! We need to fix.
Some(unsafe { self.ast.copy(&annotation.type_annotation) })
} else {
if let Expression::TSAsExpression(expr) = &pattern.right {
if !expr.type_annotation.is_keyword_or_literal() {
self.error(parameter_must_have_explicit_type(expr.type_annotation.span()));
}
}
self.infer_type_from_expression(&pattern.right)
}
} else {

View file

@ -30,3 +30,5 @@ export const fooBad2 = ({a, b} = { a: 1, b: 2 }): number => {
export function withAny(a: any = 1, b: string): void { }
export function withUnknown(a: unknown = 1, b: string): void { }
export function withTypeAssertion(a = /regular-repression-cannot-infer/ as any): void { }

View file

@ -17,6 +17,7 @@ export declare function fooBad(): number;
export declare const fooBad2: () => number;
export declare function withAny(a: any, b: string): void;
export declare function withUnknown(a: unknown, b: string): void;
export declare function withTypeAssertion(a?: any): void;
==================== Errors ====================