Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Svelte 5 - using $state for class field in TypeScript

$
0
0

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/*"]}

Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>