Open petermakeswebsites opened 1 month ago
Decorations require the experimentalDecorators in tsconfig.json
That's not the case anymore in typescript 5+ for Stage 3 decorators. Here's what the announcement says:
--experimentalDecorators
will continue to exist for the foreseeable future; however, without the flag, decorators will now be valid syntax for all new code
Describe the bug
_Note: This bug report has nothing to do with using runes in conjunction with decorations, but rather using decorations at all anywhere in the entire codebase._
This is a fairly low priority bug, if it could even be considered a bug, but given that decorations will become more popular pretty soon as they are gradually integrated into browsers, it may be worth giving some forethought. It's also possible that this is purely a typescript problem and nothing really Svelte can or should do about it.
Decorations require the
experimentalDecorators
in tsconfig.json. However,useDefineForClassFields
needs to be set tofalse
intsconfig.json
in order for them to work.On the other hand, in order for runes to work in any file,
useDefineForClassFields
needs to be set totrue
- which is the default.This creates a situation where either A) no runes work or B) no decorators work (at least field property decorators). This has nothing to do with them being used in the same class or file. It's codebase-wide.
Reproduction
Reproduction requires fiddling with
tsconfig.json
so reproduction in REPL is not possible AFAIK. Fortunately it's simple to do. Just import the followingmy-class.ts
andstate.svelte.ts
into the app."Default mode"
my-class.ts
state.svelte.ts
"Decorator mode"
my-class.ts
state.svelte.ts
Logs
Here is the piped typescript output from the compilation with
useDefineForClassFields
set tofalse
. You can see typescript decides to put the initialisers in the constructor, which breaks$state
.System Info
Severity
annoyance