Skip to content

Commit 21670e7

Browse files
authored
Fix AS Migration Guide upcasting formatting (#70)
1 parent d9b858f commit 21670e7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pages/en/developer/assemblyscript-migration-guide.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ let c: usize = a + (b as usize)
180180
// upcasting on class inheritance
181181
class Bytes extends Uint8Array {}
182182

183-
let bytes = new Bytes(2) < Uint8Array > bytes // same as: bytes as Uint8Array
183+
let bytes = new Bytes(2)
184+
// <Uint8Array>bytes // same as: bytes as Uint8Array
184185
```
185186
186187
There are two scenarios where you may want to cast, but using `as`/`<T>var` **isn't safe**:
@@ -192,15 +193,17 @@ There are two scenarios where you may want to cast, but using `as`/`<T>var` **is
192193
// downcasting on class inheritance
193194
class Bytes extends Uint8Array {}
194195

195-
let uint8Array = new Uint8Array(2) < Bytes > uint8Array // breaks in runtime :(
196+
let uint8Array = new Uint8Array(2)
197+
// <Bytes>uint8Array // breaks in runtime :(
196198
```
197199
198200
```typescript
199201
// between two types that share a superclass
200202
class Bytes extends Uint8Array {}
201203
class ByteArray extends Uint8Array {}
202204

203-
let bytes = new Bytes(2) < ByteArray > bytes // breaks in runtime :(
205+
let bytes = new Bytes(2)
206+
// <ByteArray>bytes // breaks in runtime :(
204207
```
205208
206209
For those cases, you can use the `changetype<T>` function:

0 commit comments

Comments
 (0)