Skip to content

Commit a44ef8c

Browse files
committed
wip
1 parent bff5313 commit a44ef8c

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

packages/signals/signals-runtime/src/runtime-helpers.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
interface BaseSignal {
2-
index?: number
3-
type: string
4-
time: number
5-
}
6-
7-
export type SignalOfType<
8-
AllSignals extends BaseSignal,
9-
SignalType extends AllSignals['type']
10-
> = AllSignals & { type: SignalType }
1+
import { BaseSignal, SignalOfType } from './types/shared'
112

123
/**
134
* SignalsRuntime class to manage signals
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface BaseSignal {
2+
type: string
3+
}
4+
5+
export type SignalOfType<
6+
AllSignals extends BaseSignal,
7+
SignalType extends AllSignals['type']
8+
> = AllSignals & { type: SignalType }

packages/signals/signals-runtime/src/types/web/signals.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { BaseSignal, SignalOfType } from '../shared'
2+
13
export type JSONPrimitive = string | number | boolean | null
24
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
35
export type JSONObject = { [member: string]: JSONValue }
@@ -97,8 +99,6 @@ export interface UserDefinedSignalData {
9799

98100
export type UserDefinedSignal = AppSignal<'userDefined', UserDefinedSignalData>
99101

100-
export type SignalOfType<T extends SignalTypes> = Signal & { type: T }
101-
102102
export type Signal =
103103
| InteractionSignal
104104
| NavigationSignal
@@ -111,10 +111,10 @@ export interface SegmentEvent {
111111
[key: string]: any
112112
}
113113

114-
export interface SignalsRuntimeAPI {
115-
find: <T extends SignalTypes>(
114+
export interface ISignalsRuntime<Signal extends BaseSignal> {
115+
find: <SignalType extends Signal['type']>(
116116
fromSignal: Signal,
117-
signalType: T,
118-
predicate?: (signal: SignalOfType<T>) => boolean
119-
) => SignalOfType<T> | undefined
117+
signalType: SignalType,
118+
predicate?: (signal: SignalOfType<Signal, SignalType>) => boolean
119+
) => SignalOfType<Signal, SignalType> | undefined
120120
}

packages/signals/signals-runtime/src/web-exports-globals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// all import directives will be removed in the final build
2-
import { SignalsRuntimeAPI } from './types/web/signals'
2+
import { ISignalsRuntime, Signal } from './web-exports'
33

44
// This will be appended to the generated code - dts-bundle-generator will not write declare const for whatever reason.
5-
declare const signals: SignalsRuntimeAPI
5+
declare const signals: ISignalsRuntime<Signal>
66
declare const SignalType: {
77
Interaction: 'interaction'
88
Navigation: 'navigation'

0 commit comments

Comments
 (0)