sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.04k stars 4.08k forks source link

Svelte 5: Using $state in class at outside svelte file. #9514

Closed Hunnnn77 closed 9 months ago

Hunnnn77 commented 9 months ago

Describe the bug

I'm managing states outside of svelte and changing all my writable things to $state while i'm trying svelte5 alpha. as i understood, $state is available globally, not specific .svelte files my mental model for $state is writable or solid's signal things. i don't know reason because $state in class at svelte file is perfectly works. do i need addtional steps to solve this issue?

Error Message

ReferenceError: $state is not defined

Reproduction

--TS
export default class AuthState {
  + status = $state<IAuthState['status']>('logout')
  + from = $state<IAuthState['from']>()
  - REMOVED any Writable things

  constructor(protected state: IAuthState) {
    this.status = state.status
    this.from = state.from
  }

--Svelte
<script>
   // Using getContext to bring my auth class here
</scirpt>

<div>
    {status}
    {from?.data.email}
    {from?.data.at}
</div>

Logs

No response

System Info

Window, Firefox

Severity

annoyance

brunnerh commented 9 months ago

Files using runes need to be called .svelte.ts/js, is that the case?

Hunnnn77 commented 9 months ago

@brunnerh oh, Thanks for solution, i should've taken a look at doc carefully. seems rune become typescript itself!