Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
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
12 changes: 2 additions & 10 deletions crates/oxc_isolated_declarations/src/inferrer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Original file line number Diff line number Diff line change
Expand Up @@ -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 ====================
Expand Down