-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Current Limitation
Using const to define a component prevents utilization of TypeScript's namespaces to encapsulate runtime entities, only types can be defined with the namespace.
import {component} from "babel-plugin-solid-undestructure"
export const Greeting = component(({name, greeting="Hello"}:Greeting.Props) => <h1>{greeting} {name}</h1>)
export namespace Greeting{
export type Props = {
name: string
greeting?: ("Hello" | "Howdy")
}
/* Error: Cannot redeclare block-scoped variable 'Greeting'.ts(2451) */
//export function alert({name, greeting="Hello"}:Props){
// window.alert(`${greeting} ${name}`)
//}
}Proposed Solution
An undestructure compile-type function annotation that can be used within a function component would allow full utilization of TypeScript's namespaces.
This could also allow solid-undestructure's functionality to be utilized in non-component utility functions. I'm still not 100% clear on the use cases for this, but from @ryansolid's comment @ Discord, it seems that it could prevent reactivity from being broken in certain scenarios.
import {undestructure} from "babel-plugin-solid-undestructure"
export function Greeting(props:Greeting.Props){
/* Preferable to `splitProps` in some cases,
* because it exposes variables directly into the scope
* rather than encapsulating them, and also doesn't require
* explicit definition of keys to be split. */
const {name, greeting="Hello"} = undestructure(props)
return <h1>{greeting} {name}</h1>
}
export namespace Greeting{
export type Props = {
name: string
greeting?: ("Hello" | "Howdy")
}
/* Works, no error. */
export function alert({name, greeting="Hello"}:Props){
window.alert(`${greeting} ${name}`)
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
