NativeScript / NativeScript/angular

Angular 22 compatibility, EventData types are not correctly inferred from templates

未關閉
#170 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
TypeScript
星號
55
分支
13
平均合併
16 分鐘
30 天內合併 PR
1

描述

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

✔ Component nativescript has 9.0.6 version and is up to date.
✔ Component @nativescript/core has 9.0.20 version and is up to date.
✔ Component @nativescript/ios has 9.0.3 version and is up to date.
✔ Component @nativescript/android has 9.0.4 version and is up to date.

            "@angular/animations": "22.0.1",
	"@angular/common": "22.0.1",
	"@angular/compiler": "22.0.1",
	"@angular/core": "22.0.1",
	"@angular/forms": "22.0.1",
	"@angular/platform-browser": "22.0.1",
	"@angular/platform-browser-dynamic": "22.0.1",
	"@angular/router": "22.0.1",
	"@angular-devkit/build-angular": "22.0.1",
	"@angular/build": "22.0.1",
	"@ngtools/webpack": "22.0.1",
	"typescript": "6.0.3",
	"@nativescript/angular": "22.0.0-dev.0",
	"@nativescript/core": "9.0.20",
	"@nativescript/iqkeyboardmanager": "3.0.0",
	"@nativescript/localize": "5.2.0",
	"@nativescript/secure-storage": "4.0.1",
	"@nativescript/theme": "3.1.0",
	"rxjs": "7.8.2",
	"sass": "1.100.0",
	"typescript": "6.0.3"

Describe the bug
With the Angular 22 type checking I see 2 compatibility problems, both related to template checks. I need to say, my app is running perfectly fine. The problems I am seeing are from type checking only!

  1. this can be seen when activating
    "angularCompilerOptions": {"strictDomEventTypes": true}

It seems like angular cannot narrow down parameter types. I get about 400 errors related to the usage of $event in method calls. it is everywhere interpretet as Event rather than the related Nativescript EventData or derived type.. Below some examples to understand the pattern

error TS2345: Argument of type 'Event' is not assignable to parameter of type 'EventData'.
Type 'Event' is missing the following properties from type 'EventData': eventName, object
2 (shouldOverrideUrlLoading)="onOverrideUrlLoading($event)" (loaded)="onPlayerLoaded($event)" iosAllowInlineMediaPlayback="true" backgroundColor="black">

ERROR in src/app/modules/selection/pages/add-edit-meal/add-edit-meal.component.html:35:105 - error TS2345: Argument of type 'Event' is not assignable to parameter of type 'EventData'.
Type 'Event' is missing the following properties from type 'EventData': eventName, object
35 (textChange)="onCheckMealChange($event)" class="text-field recipe-field" (tap)="onTextFieldSetFocus($event)">


  1. Second problem can be seen when activating
    "angularCompilerOptions": {"strictDomEventTypes": false,}
    "strictDomLocalRefTypes": true,

When I try to use a template reference in a function
<Label #idElement (tap)="myFunction(idElement)">
and want to use it in component as
public myFunction(arg:View){...}

I get the error
Argument of type 'HTMLElement' is not assignable to parameter of type 'View'.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先,使用 Angular 22 和所示的 angularCompilerOptions 設定重現範本檢查錯誤。使用 $event 和 #idElement 範例比較 strictDomEventTypes true 與 strictDomLocalRefTypes true。當 NativeScript 事件處理常式推斷出衍生自 EventData 的型別,且範本參照被辨識為 View 而非 HTMLElement 時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
angular, typescript
領域
frontend
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。