Skip to content

Commit d396d62

Browse files
Copilothotlong
andauthored
fix(ts6): fix TypeScript 6.0.2 compatibility errors across packages
Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/219a023f-18c7-4a92-80f1-313c9be66e8b Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent bd94b13 commit d396d62

12 files changed

Lines changed: 22 additions & 32 deletions

File tree

apps/site/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"baseUrl": ".",
4+
"ignoreDeprecations": "6.0",
45
"target": "ESNext",
56
"lib": ["dom", "dom.iterable", "esnext"],
67
"allowJs": true,

packages/core/src/errors/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export class ObjectUIError extends Error {
120120
this.name = 'ObjectUIError';
121121

122122
// Maintains proper stack trace for where error was thrown (only in V8)
123-
if (Error.captureStackTrace) {
124-
Error.captureStackTrace(this, this.constructor);
123+
if ((Error as any).captureStackTrace) {
124+
(Error as any).captureStackTrace(this, this.constructor);
125125
}
126126
}
127127

@@ -203,7 +203,7 @@ function interpolate(
203203
params: Record<string, string>,
204204
): string {
205205
return template.replace(/\$\{(\w+)\}/g, (_match, key: string) => {
206-
if (!(key in params) && typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {
206+
if (!(key in params) && (globalThis as any).process?.env?.NODE_ENV !== 'production') {
207207
console.warn(`[ObjectUI] Missing interpolation parameter "${key}" in error message template.`);
208208
}
209209
return params[key] ?? `\${${key}}`;
@@ -254,8 +254,7 @@ export function createError(
254254
*/
255255
export function formatErrorMessage(
256256
error: ObjectUIError,
257-
isDev: boolean = typeof process !== 'undefined' &&
258-
process.env?.NODE_ENV !== 'production',
257+
isDev: boolean = (globalThis as any).process?.env?.NODE_ENV !== 'production',
259258
): string {
260259
const entry = ERROR_CODES[error.code];
261260

packages/core/src/protocols/DndProtocol.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ export function resolveDndConfig(config: DndConfig): ResolvedDndConfig {
9595
* @returns Component props object for a draggable element
9696
*/
9797
export function createDragItemProps(item: DragItem): DragItemProps {
98-
const ariaLabel = typeof item.ariaLabel === 'string'
99-
? item.ariaLabel
100-
: item.ariaLabel?.defaultValue;
101-
102-
const label = typeof item.label === 'string'
103-
? item.label
104-
: item.label?.defaultValue;
98+
const ariaLabel = item.ariaLabel;
99+
const label = item.label;
105100

106101
return {
107102
draggable: !(item.disabled ?? false),
@@ -127,13 +122,8 @@ export function createDragItemProps(item: DragItem): DragItemProps {
127122
* @returns Component props object for a droppable area
128123
*/
129124
export function createDropZoneProps(zone: DropZone): DropZoneProps {
130-
const ariaLabel = typeof zone.ariaLabel === 'string'
131-
? zone.ariaLabel
132-
: zone.ariaLabel?.defaultValue;
133-
134-
const label = typeof zone.label === 'string'
135-
? zone.label
136-
: zone.label?.defaultValue;
125+
const ariaLabel = zone.ariaLabel;
126+
const label = zone.label;
137127

138128
return {
139129
'aria-dropeffect': zone.dropEffect ?? 'move',

packages/core/src/protocols/KeyboardProtocol.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ export interface KeyboardEventLike {
8383
* @returns Fully resolved keyboard navigation configuration
8484
*/
8585
export function resolveKeyboardConfig(config: KeyboardNavigationConfig): ResolvedKeyboardConfig {
86-
const ariaLabel = typeof config.ariaLabel === 'string'
87-
? config.ariaLabel
88-
: config.ariaLabel?.defaultValue;
86+
const ariaLabel = config.ariaLabel;
8987

9088
return {
9189
shortcuts: config.shortcuts ?? [],

packages/core/src/protocols/NotificationProtocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function resolveTranslatableString(value: string | { key: string; defaultValue?:
142142
*/
143143
export function specNotificationToToast(notification: SpecNotification): ToastNotification {
144144
const actions: ToastAction[] = (notification.actions ?? []).map((a: NotificationAction) => ({
145-
label: typeof a.label === 'string' ? a.label : a.label?.defaultValue ?? '',
145+
label: a.label,
146146
action: a.action,
147147
variant: a.variant ?? 'primary',
148148
}));

packages/core/src/utils/debug.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export function isDebugEnabled(): boolean {
9393
if (g === true || g === 'true') return true;
9494

9595
// 3. process.env
96-
if (typeof process !== 'undefined' && process.env?.OBJECTUI_DEBUG === 'true') return true;
96+
const proc = (globalThis as any).process;
97+
if (proc?.env?.OBJECTUI_DEBUG === 'true') return true;
9798

9899
return false;
99100
} catch {

packages/data-objectstack/src/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export class ObjectStackError extends Error {
2828
this.name = 'ObjectStackError';
2929

3030
// Maintains proper stack trace for where error was thrown (only in V8)
31-
if (Error.captureStackTrace) {
32-
Error.captureStackTrace(this, this.constructor);
31+
if ((Error as any).captureStackTrace) {
32+
(Error as any).captureStackTrace(this, this.constructor);
3333
}
3434
}
3535

packages/plugin-grid/src/ObjectGrid.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ function useGridTranslation() {
9191
}
9292
}
9393

94-
/** Resolve an I18nLabel (string | {key, defaultValue}) to a plain string. */
94+
/** Resolve an I18nLabel (string) to a plain string. */
9595
function resolveColumnLabel(label: string | I18nLabel | undefined): string | undefined {
9696
if (label == null) return undefined;
97-
if (typeof label === 'string') return label;
98-
return label.defaultValue || label.key;
97+
return typeof label === 'string' ? label : undefined;
9998
}
10099

101100
export interface ObjectGridProps {

packages/plugin-grid/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default defineConfig({
99
dts({
1010
insertTypesEntry: true,
1111
include: ['src'],
12+
compilerOptions: { rootDir: '../../' },
1213
}),
1314
],
1415
resolve: {

packages/react/src/SchemaRenderer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class SchemaErrorBoundary extends Component<
7272
render() {
7373
if (this.state.hasError && this.state.error) {
7474
const error = this.state.error;
75-
const isDev = process.env.NODE_ENV !== 'production';
75+
const isDev = (globalThis as any).process?.env?.NODE_ENV !== 'production';
7676
const objuiError = isObjectUIError(error) ? error as ObjectUIError : null;
7777

7878
return (
@@ -189,7 +189,7 @@ export const SchemaRenderer = forwardRef<any, { schema: SchemaNode } & Record<st
189189
return (
190190
<div className="p-4 border border-red-500 rounded text-red-500 bg-red-50 my-2" role="alert">
191191
<p className="font-medium">Unknown component type: <strong>{evaluatedSchema.type}</strong></p>
192-
{process.env.NODE_ENV !== 'production' && (
192+
{(globalThis as any).process?.env?.NODE_ENV !== 'production' && (
193193
<p className="text-xs mt-1">💡 {errorInfo.suggestion} (OBJUI-001)</p>
194194
)}
195195
<pre className="text-xs mt-2 overflow-auto">{JSON.stringify(evaluatedSchema, null, 2)}</pre>

0 commit comments

Comments
 (0)