diff --git a/cli/doc/printer.rs b/cli/doc/printer.rs index 7a6b9e731c..f7f41079db 100644 --- a/cli/doc/printer.rs +++ b/cli/doc/printer.rs @@ -127,6 +127,9 @@ fn render_params(params: Vec) -> String { } fn render_ts_type(ts_type: doc::ts_type::TsTypeDef) -> String { + if ts_type.kind.is_none() { + return "".to_string(); + } let kind = ts_type.kind.unwrap(); match kind { TsTypeDefKind::Array => { diff --git a/cli/doc/tests.rs b/cli/doc/tests.rs index f8e693c9a1..7f2c186396 100644 --- a/cli/doc/tests.rs +++ b/cli/doc/tests.rs @@ -161,6 +161,19 @@ export function foo(a: string, b?: number, cb: (...cbArgs: unknown[]) => void, . ); } +#[tokio::test] +async fn format_type_predicate() { + let source_code = r#" +export function isFish(pet: Fish | Bird): pet is Fish { + return (pet as Fish).swim !== undefined; +} +"#; + let loader = + TestLoader::new(vec![("test.ts".to_string(), source_code.to_string())]); + let entries = DocParser::new(loader).parse("test.ts").await.unwrap(); + super::printer::format(entries); +} + #[tokio::test] async fn export_fn2() { let source_code = r#"