Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sor4chi committed Nov 9, 2024
1 parent d67cd1b commit 91af8a0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions checker/specification/staging.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Currently implementing:

> This file is for work-in-progress and can help separating features that are being implemented to regressions
### Printing

#### Template Literal Type

```ts
const invalidStr: `Hi${string}` = 'Hello, there!';
```

- Type "Hello, there!" is not assignable to type `Hi${string}`
34 changes: 33 additions & 1 deletion checker/src/types/printing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,39 @@ pub fn print_type_into_buf<C: InformationChain>(
unreachable!()
}
},
_constructor => {
constructor => {
if let Constructor::BinaryOperator { result: result_ty, lhs, rhs, .. } = constructor
{
if *result_ty != TypeId::NUMBER_TYPE
&& !matches!(
types.get_type_by_id(*result_ty),
Type::PartiallyAppliedGenerics(_) | Type::RootPolyType(_)
) {
buf.push('`');
{
let ty = types.get_type_by_id(*lhs);
if let Type::Constant(cst) = ty {
buf.push_str(&cst.as_js_string());
} else {
buf.push_str("${");
print_type_into_buf(*lhs, buf, cycles, args, types, info, debug);
buf.push('}');
}
}
{
let ty = types.get_type_by_id(*rhs);
if let Type::Constant(cst) = ty {
buf.push_str(&cst.as_js_string());
} else {
buf.push_str("${");
print_type_into_buf(*rhs, buf, cycles, args, types, info, debug);
buf.push('}');
}
}
buf.push('`');
return;
}
}
let base = get_constraint(ty, types).unwrap();
print_type_into_buf(base, buf, cycles, args, types, info, debug);
}
Expand Down

0 comments on commit 91af8a0

Please sign in to comment.