Closed
Description
Given the following AssemblyScript file:
class C {
x: u8 | null;
y: null | u8;
}
I get the following errors:
$ asc tmp.ts
ERROR TS1005: 'null' expected.
:
3 │ y: null | u8 = null; // Error, TS1005: 'null' expected.
│ ~~
└─ in tmp.ts(3,13)
FAILURE 1 parse error(s)
I would expect both lines to work.
Compiling the following TypeScript code (note the added !
's) it works just fine:
class C {
x!: number | null;
y!: null | number;
}
It would seem that | null
is only allowed at the end. The solution seems easy enough, seems to be somewhere near src/parser.ts (line 530ish) if I had to guess. I am not familiar with this codebase, but I wouldn't mind making a PR this if need be!
Possible related: #2300