Skip to content

Commit 4105ec6

Browse files
authored
Merge pull request nullstack#364 from GuiDevloper/types-improvements
Sync `ref` types in JSX & Context
2 parents f2fa1b4 + 7c9370d commit 4105ec6

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

types/ClientContext.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { NullstackWorker } from './Worker'
1111
/**
1212
* @see https://nullstack.app/context
1313
*/
14-
interface BaseNullstackClientContext {
14+
interface BaseNullstackClientContext<TProps = unknown> {
1515
/**
1616
* Callback function that bootstrap the context for the application.
1717
*/
@@ -120,15 +120,17 @@ interface BaseNullstackClientContext {
120120
*
121121
* @see https://nullstack.app/refs#complex-refable-components
122122
*/
123-
ref?: { property?: string | number; object?: any } | ((context: NullstackClientContext) => void)
123+
ref?: TProps extends { ref: any } ? TProps['ref'] : {
124+
object: any
125+
property: string | number
126+
}
124127

125128
/**
126129
* Ref element.
127130
*
128131
* @see https://nullstack.app/refs#complex-refable-components
129132
*/
130-
131133
element?: HTMLElement
132134
}
133135

134-
export type NullstackClientContext<TProps = unknown> = BaseNullstackClientContext & TProps
136+
export type NullstackClientContext<TProps = unknown> = BaseNullstackClientContext<TProps> & TProps

types/JSX.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ type Booleanish = boolean | 'true' | 'false'
4444
// Nullstack Elements
4545
// ----------------------------------------------------------------------
4646

47-
export interface Attributes<HTMLElementType> {
47+
export interface Attributes<HTMLElementType = unknown> {
4848
html?: string
4949
source?: object
5050
bind?: any
5151
debounce?: number
52-
ref?: HTMLElementType | ((context?: Partial<NullstackClientContext>) => void)
52+
ref?: HTMLElementType | ((context?: Partial<NullstackClientContext>) => void) | NullstackClientContext['ref']
5353
'data-'?: any
5454
children?: NullstackNode
5555
route?: string
5656
persistent?: boolean
5757
[key: string]: any
5858
}
5959

60-
export interface NullstackAttributes<T> extends Attributes<T> {}
60+
export interface NullstackAttributes extends Attributes {}
6161

62-
export interface ClassAttributes<T> extends Attributes<T> {
62+
export interface ClassAttributes<T = unknown> extends Attributes<T> {
6363
key?: string
6464
}
6565

@@ -1233,18 +1233,18 @@ export interface SVGAttributes<T> extends AriaAttributes, DOMAttributes<T> {
12331233
y?: number | string
12341234
}
12351235

1236-
export type ElementTagHTMLAttributes = AllHTMLAttributes<'div'> & {
1236+
export type ElementTagHTMLAttributes = AllHTMLAttributes<HTMLDivElement> & {
12371237
tag?: string
12381238
}
12391239

1240-
type ExoticElements = Record<string, DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>>
1240+
type ExoticElements = Record<string, DetailedHTMLProps<HTMLAttributes<HTMLElement> | SVGProps<any> | ElementTagHTMLAttributes, HTMLElement>>
12411241

12421242
declare global {
12431243
namespace JSX {
12441244
type Element = NullstackNode
12451245

1246-
type IntrinsicAttributes = NullstackAttributes<unknown>
1247-
type IntrinsicClassAttributes = ClassAttributes<unknown>
1246+
type IntrinsicAttributes = NullstackAttributes
1247+
type IntrinsicClassAttributes = ClassAttributes
12481248

12491249
interface AllElements {
12501250
// HTML

0 commit comments

Comments
 (0)