I have a class:
class TestClass { prop = $state('test');}
It works in .svelte.js
and .svelte
files with <script lang="js">
, but doesn't work in .svelte.ts
and .svelte
files with <script lang="ts">
.Getting this error:
CompileError: $state(...) can only be used as a variable declaration initializer or a class field
Am I doing anything wrong or Svelte 5 just doesn't support TS class field states yet?
My tsconfig.json
file content:
{"extends": "./.svelte-kit/tsconfig.json","compilerOptions": {"emitDecoratorMetadata": true,"experimentalDecorators": true,"moduleResolution": "node","module": "es2020","lib": ["es2020", "dom"],"target": "es2019","importsNotUsedAsValues": "error","isolatedModules": true,"resolveJsonModule": true,"sourceMap": true,"esModuleInterop": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true,"baseUrl": ".","allowJs": true,"checkJs": true,"paths": { .... } },"include": [ .... ],"exclude": ["node_modules/*"]}