Skip to content
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
4 changes: 3 additions & 1 deletion crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ impl<'a> TSType<'a> {
/// Check if type maybe `undefined`
pub fn is_maybe_undefined(&self) -> bool {
match self {
TSType::TSUndefinedKeyword(_) => true,
TSType::TSAnyKeyword(_)
| TSType::TSUnknownKeyword(_)
| TSType::TSUndefinedKeyword(_) => true,
TSType::TSUnionType(un) => un.types.iter().any(Self::is_maybe_undefined),
_ => false,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'a> IsolatedDeclarations<'a> {
if matches!(ts_type, TSType::TSTypeReference(_)) {
self.error(implicitly_adding_undefined_to_type(param.span));
} else if !ts_type.is_maybe_undefined() {
// union with undefined
// union with `undefined`
return self.ast.ts_type_annotation(
SPAN,
self.ast.ts_type_union_type(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ export function fooBad([a, b] = [1, 2]): number {
export const fooBad2 = ({a, b} = { a: 1, b: 2 }): number => {
return 2;
}


export function withAny(a: any = 1, b: string): void { }
export function withUnknown(a: unknown = 1, b: string): void { }
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export declare function fnDeclBad2<T>(p: T, r2: T): void;
export declare function fnDeclBad3<T>(p: T, rParam?: T, r2: T): void;
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;


==================== Errors ====================
Expand Down