TypeScript definitions #1609
Replies: 3 comments 6 replies
-
We have a v3 definition we use locally so I can see about having it added through PR if there is other interest. It's not complete but here is rough draft of our current one: our internal alpine.d.ts
|
Beta Was this translation helpful? Give feedback.
-
type AlpineWatch = ( targetProperty: string, callback: ( ( newValue: any, oldValue?: any ) => void ) ) => void;
type AlpineMagicProperties<AlpineGlobalStore = Record<string, V>> = {
$el?: HTMLElement;
$refs?: { [xRefId: string]: HTMLElement };
$watch?: AlpineWatch;
$nextTick?: ( functionToCall: ( () => void ) ) => void;
$store?: AlpineGlobalStore;
$dispatch?: <T = any>( eventName: string, eventDetail?: T ) => void;
};
type AlpineMandatoryProps = {
init?: () => void,
}
declare type AlpineComponent<Props extends BaseAlpineProps, AlpineGlobalStore = {}> = {
(): AlpineMandatoryProps & Props & AlpineMagicProperties<AlpineGlobalStore>;
};
interface BaseAlpineProps {
init?: ( () => void ) | ( () => Promise<void> );
}
interface AlpineRoot {
store,
start,
directive,
version: string,
}
declare module "alpinejs" {
type AlpineDirectiveCallback = ( p1 : HTMLElement, p2 : any, p3: any ) => void;
type AlpineRootCallback = ( ( alpineRoot : Alpine ) => void );
function store<R>( storeName: string, value : R ) : void;
function store<R>( storeName: string ) : R;
function directive( directiveName : string, cb : AlpineDirectiveCallback );
function plugin( alpineRootCallBack : AlpineRootCallback ) : void;
function data( dataName: string, dataInitializer: () => Record<string, V> ): void;
function effect( effectCallback: () => void ): void;
function reactive<T>( initialData: Record<string, T> ): Record<string, T>;
function magic( magicName: string, callback: ( el: HTMLElement, alpineObj: { Alpine: Alpine } ) => any ): void;
function start() : void;
export default Alpine = {
version: string,
store,
start,
directive,
plugin,
data,
effect,
reactive,
magic
};
} Adding the definition you added with proper syntax highlighting |
Beta Was this translation helpful? Give feedback.
-
Good question. No plans to rewrite in TS. (I know everyone unanimously loves it, I just really like plain JS) However, I'm definitely open to adding TS definitions. Because we would have to keep it in sync with core and maintain it long term, I'd like for this to be refined by the community and then when there's sufficient demand, we can pull it into core. Maybe this is the best place to gauge that interest and hold that discussion. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hello, I've just been introduced to Alpine.js - and I love it.
The only problem I currently have is that it has no Typescript definition files, and I write primarily TS.
I'm 100% sure that I am not the only one - so my main question is:
Is there a plan to create .d.ts files for Alpine?
Beta Was this translation helpful? Give feedback.
All reactions