-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReadonlySignal
should not inherit from Signal
type
#585
Comments
This is the intended behavior I believe. The purpose of Edit: Besides, the only API to return As such, I'll close this on out. |
I had a bug in my code where I had a component that consumed a This can be fixed by doing the inheritance the other way around. This is clearly a bug in the library as the library is using typescript wrong. this is like "Apple" is of type string, but string is not type of "Apple" |
I don't see how this could possibly be an issue of the types, passing a
This is very much not the case. It sounds more like a misunderstanding of what this type is meant to guard against. A |
Hey, Sorry. I had my report the wrong way around (I edited it). Sorry for the confusion. It should be like this: const numberSingal: ReadonlySignal<number> = useSignal<number>(0) // ok
const numberSignal: Signal<number> = useComputed<number>(0) // should error import { ReadonlySignal, Signal } from '@preact/signals-core'
declare const readonlySignal: ReadonlySignal<number>
const writeableSignal: Signal<number> = readonlySignal // should error, doesn't
writeableSignal.value = 5 // runtime error!
declare const writeableSignal2: Signal<number>
const readonlySignal2: ReadonlySignal<number> = writeableSignal2 // ok, but only because TypeScript doesn't correctly check readonly (soundness)
readonlySignal2.value = 5 // correctly errors The problem is that the only difference between the two types is if a property is readonly or not. There is a soundness bug in Typescript. Currently, the |
Gotcha, that makes more sense. |
Environment
@preact/signals
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
This assignment should not be allowed as signal is not readonly
the bug is here:
https://github.com/preactjs/signals/blob/main/packages/core/src/index.ts#L660
Expected behavior
There should be a type error
The text was updated successfully, but these errors were encountered: