-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix(signals): allow using signalStore and signalState in TS libs #4152
Conversation
✅ Deploy Preview for ngrx-io canceled.
|
Prettify< | ||
SignalStoreSlices<FeatureResult['state']> & | ||
FeatureResult['signals'] & | ||
FeatureResult['methods'] & | ||
SignalStateMeta<Prettify<FeatureResult['state']>> | ||
FeatureResult['methods'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A workaround for this TS bug is to always put a unique symbol inside of the named type.
Before:
The STATE_SIGNAL
was appended to the dynamic SignalStore
type by prettifying the intersection.
const CounterStore = signalStore(withState({ count: 0 }));
// type: Type<{ count: Signal<number>; [STATE_SIGNAL]: WritableSignal<{ count: number }> }>
After:
The STATE_SIGNAL
is always exported as a part of the StateSignal
type.
const CounterStore = signalStore(withState({ count: 0 }));
// type: Type<{ count: Signal<number>; } & StateSignal<{ count: number }>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
StateSignal
has to be added to the public APIs index.ts
as well, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed. We can keep it private.
@@ -8,7 +8,7 @@ import { IsKnownRecord } from './ts-helpers'; | |||
|
|||
// An extended Signal type that enables the correct typing | |||
// of nested signals with the `name` or `length` key. | |||
interface Signal<T> extends NgSignal<T> { | |||
export interface Signal<T> extends NgSignal<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This export fixes the same compilation error in TS libraries with declaration: true
when signalState
is used. The problem was caused by another unique symbol - Angular's SIGNAL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Please, somebody approve it) |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Closes #4151
What is the new behavior?
signalStore
andsignalState
can be used/exported in projects that havetsconfig
with"declaration": true
.Does this PR introduce a breaking change?
Other information
This is a workaround for the following TS bug: microsoft/TypeScript#37888