Loading...
Loading...
This Skill summarizes common TypeScript issues and their solutions in Lynx development, mainly covering environment configuration, type extending, event handling, components, and ReactLynx advanced usages. Trigger Scenarios: - User inputs TypeScript error messages related to Lynx and seeks fix suggestions - LSP diagnoses Lynx-related TypeScript errors, proactively invoke query to get fix solutions - User asks about TypeScript best practices or common errors related to Lynx, proactively invoke query to provide guidance - User requests to configure the TypeScript environment of the current project to support Lynx development, proactively invoke query to provide configuration steps
npx skill4agent add lynx-community/skills lynx-typescripttsconfig.jsontsconfig.jsonisolatedModules{
"compilerOptions": {
"isolatedModules": true,
"paths": {
"@/*": ["./src/*"]
}
}
}@lynx-js/types@lynx-js/reactrspeedy-env.d.tssrc/rspeedy-env.d.ts/// <reference types="@rspeedy/core/client" />@rspeedy/corejsxImportSource@lynx-js/reacttsconfig.json{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@lynx-js/react"
}
}lynx.__globalPropsdeclare module '@lynx-js/types' {
interface GlobalProps {
appTheme: string;
title: string;
// Add other custom global properties
}
}
export {};lynx.__globalProps.appThemeuseInitData()declare module '@lynx-js/react' {
interface InitData {
userInfo: {
name: string;
id: number;
};
// Add other initialization data properties
}
}
export {};useInitData().userInfoIntrinsicElementsimport type * as Lynx from '@lynx-js/types';
import type { CSSProperties } from '@lynx-js/types';
declare module '@lynx-js/types' {
interface IntrinsicElements extends Lynx.IntrinsicElements {
'custom-input': {
'bindcustom-event'?: (e: { type: 'custom-event'; detail: { value: string } }) => void;
value?: string;
class?: string;
className?: string;
style?: string | CSSProperties;
};
}
}NativeModulesdeclare module '@lynx-js/types' {
interface NativeModules {
NativeLocalStorageModule: {
getStorageItem(key: string): string | null;
setStorageItem(key: string, value: string): void;
};
}
}
export {};lynxlynx.myMethoddeclare module '@lynx-js/types' {
interface Lynx {
myMethod(param: string): void;
customProperty: number;
}
}
export {};lynx.myMethod('test')anybindtapbindtouchstartdetailtoucheschangedTouches// Example: Handling a tap event
const handleTap = (event: any) => { // Using any is not recommended
console.log(event);
};
// Recommended approach: Define event interfaces or use inferred types
import type { TouchEvent } from '@lynx-js/types';
// Usage example
const handleButtonTap = (e: TouchEvent) => {
const { dataset } = e.currentTarget;
console.log('Tapped!', dataset);
};@lynx-js/lynx-ui@lynx-js/lynx-ui-button@lynx-js/lynx-ui-scroll-viewuseRefimport { ScrollView } from '@lynx-js/lynx-ui-scroll-view';
import type { ScrollViewRef, ScrollViewProps } from '@lynx-js/lynx-ui-scroll-view';
import { useRef } from '@lynx-js/react';
function App() {
// Explicitly specify the Ref type
const scrollViewRef = useRef<ScrollViewRef>(null);
const handleScroll: ScrollViewProps['onScroll'] = (e) => {
console.log('Scrolled:', e.detail);
};
return (
<ScrollView
ref={scrollViewRef}
onScroll={handleScroll}
// ...
/>
);
}import { useMainThreadRef, runOnMainThread } from '@lynx-js/react';
function AnimationComponent() {
// Define the data type stored in MainThreadRef
const widthRef = useMainThreadRef<number>(0);
const handleTap = () => {
// Call main thread logic from the background thread
runOnMainThread(widthRef, (ref) => {
// This callback executes on the main thread
ref.current += 10;
console.log('New width:', ref.current);
});
};
return <view bindtap={handleTap} />;
}lynxquerySelector// Select element
const element = lynx.querySelector('#my-id');
// The type of element is Element | null
// Register data processors (functional)
lynx.registerDataProcessors({
defaultDataProcessor: (data) => {
return data;
}
});package.json@lynx-js/types@lynx-js/reactpathsd.tsimport {} from "@lynx-js/react"declare module '@lynx-js/types'd.tsexport {}