From 57438b6acc84610a0ee3da3b0086ab4b3aae3a4d Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 19 Feb 2026 13:00:04 +0900 Subject: [PATCH] Change typing of application specific ArSyncModel export To eliminate "is defined but only used as a type" warning --- lib/ar_sync/type_script.rb | 10 +++++++--- test/ts_test.rb | 4 ++++ test/type_test.ts | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/ar_sync/type_script.rb b/lib/ar_sync/type_script.rb index 68afcc5..1e89127 100644 --- a/lib/ar_sync/type_script.rb +++ b/lib/ar_sync/type_script.rb @@ -53,10 +53,14 @@ def self.generate_model_script import { TypeRequest } from './types' import DataTypeFromRequest from './DataTypeFromRequest' import { default as ArSyncModelBase } from 'ar_sync/core/ArSyncModel' - declare class ArSyncModel extends ArSyncModelBase> { - constructor(r: R, option?: { immutable: boolean }) + import ConnectionAdapter from 'ar_sync/core/ConnectionAdapter' + + type ArSyncModel = ArSyncModelBase> + const ArSyncModel = ArSyncModelBase as unknown as { + new (r: R, option?: { immutable: boolean }): ArSyncModel + setConnectionAdapter(adapter: ConnectionAdapter): void } - export default ArSyncModelBase as typeof ArSyncModel + export default ArSyncModel CODE end diff --git a/test/ts_test.rb b/test/ts_test.rb index eeaa35e..b67b256 100644 --- a/test/ts_test.rb +++ b/test/ts_test.rb @@ -26,5 +26,9 @@ def test_typed_files output = output.lines.grep(/type_test/) puts output assert output.empty? + + output = `./node_modules/typescript/bin/tsc --lib es2017,dom --noEmit test/generated_typed_files/*.ts` + puts output + assert output.empty? end end diff --git a/test/type_test.ts b/test/type_test.ts index d351232..b6c79cf 100644 --- a/test/type_test.ts +++ b/test/type_test.ts @@ -5,6 +5,7 @@ import * as ActionCable from 'actioncable' ArSyncModel.setConnectionAdapter(new ActionCableAdapter(ActionCable)) type IsEqual = [T, U] extends [U, T] ? true : false +type IsNotEqual = IsEqual extends true ? false : true function isOK(): T | undefined { return } type IsStrictMode = string | null extends string ? false : true type TypeIncludes = IsEqual, U> @@ -13,6 +14,7 @@ isOK() const [hooksData1] = useArSyncModel({ api: 'currentUser', query: 'id' }) isOK>() +isOK>() const [hooksData2] = useArSyncModel({ api: 'currentUser', query: { '*': true, foo: true } }) isOK>() const [hooksData3] = useArSyncFetch({ api: 'currentUser', query: 'id' }) @@ -22,6 +24,7 @@ isOK>() const data1 = new ArSyncModel({ api: 'currentUser', query: 'id' }).data! isOK>() +isOK>() const data2 = new ArSyncModel({ api: 'currentUser', query: ['id', 'name'] }).data! isOK>() const data3 = new ArSyncModel({ api: 'currentUser', query: '*' }).data!