Skip to content

Commit 8045159

Browse files
committed
Support TypeScript 3.9 and 4.x
To make tabris TypeScript 4.x-compliant some changes are needed in the type declarations: * The "properties" parameter of "set" overrides need to assignable to their respective type in the super class. This is not the case if properties are explicitly excluded via "Omit" but included in the super class. Various other mechanism to exclude read-only properties either don't work with specific TypeScript versions or cause breaking changes. Therefore these overrides are removed. Regrettably this means that it is now possible (at compile-time) to use "set" to set read-only values, though they are still excluded from the constructors. * The same issue applies to jsxAttributes, but here a workaround is possible: Instead of omitting attribute they are joined with "never". This means they are still auto-suggested by the IDE, but actually using them causes a compile error. This workaround is possible because it is assumed that the JSXAttribues<T> type is (unlike Properties<T>) is never used outside of class declarations. * NativeObject property "_nativeType" must be declared with an explicit getter to able to override it with one, as is the established way to define it in code. To allow this the declarations generator and api json schema need to be extended. This includes a minor unrelated fix in api-schema.d.ts * d.ts files may can longer be linted by eslint. The reason for this is unclear. Change-Id: I58fbceab2df94f03ebe658173965d5fdc7b60751
1 parent 38a5517 commit 8045159

22 files changed

+41
-198
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tools/*.d.ts
1+
*.d.ts
22
test/typescript/*
33
build
44
node_modules

.eslintrc.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,6 @@
412412
}
413413
]
414414
}
415-
},
416-
{
417-
"files": [
418-
"*.d.ts"
419-
],
420-
"rules": {
421-
"max-len": "off",
422-
"no-redeclare": "off",
423-
"no-var": "off",
424-
"@typescript-eslint/no-explicit-any": "off",
425-
"@typescript-eslint/explicit-member-accessibility": "off"
426-
}
427415
}
428416
]
429417
}

doc/api/AlertDialog.json

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,9 @@
5151
"const": true,
5252
"readonly": true,
5353
"ts_only": true,
54-
"type": "JSXAttributes<Omit<this, 'textInputs'>> & {children?: Flatten<string|TextInput>}"
54+
"type": "JSXAttributes<this> & {children?: Flatten<string|TextInput>, textInputs?: never}"
5555
}
5656
},
57-
"methods": {
58-
"set": [
59-
{
60-
"ts_only": true,
61-
"generics": [
62-
{
63-
"name": "T",
64-
"extends": "NativeObject",
65-
"default": "this"
66-
}
67-
],
68-
"parameters": [
69-
{
70-
"name": "properties",
71-
"type": "Properties<Omit<T, 'textInputs'>>"
72-
}
73-
],
74-
"description": "Sets all key-value pairs in the properties object.",
75-
"returns": "this"
76-
}
77-
]
78-
},
7957
"events": {
8058
"close": {
8159
"description": "Fired when the dialog was closed for any reason.",

doc/api/CollectionView.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"parameters": [
153153
{
154154
"name": "properties",
155-
"type": "Properties<Omit<T, 'firstVisibleIndex' | 'lastVisibleIndex'>> & Partial<Pick<this, 'cellHeight' | 'cellType' | 'createCell'>>"
155+
"type": "Properties<T> & Partial<Pick<this, 'cellHeight' | 'cellType' | 'createCell'>>"
156156
}
157157
],
158158
"description": "Sets all key-value pairs in the properties object as widget properties.\n\n**Important TypeScript note:** When called on `this` you may need to specify your custom type like this: `this.set<MyComponent>({propA: valueA});`",

doc/api/NativeObject.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"_nativeType": {
3333
"readonly": true,
3434
"protected": true,
35-
"type": "string"
35+
"type": "string",
36+
"separateAccessors": true
3637
},
3738
"_isDisposed": {
3839
"protected": true,

doc/api/NavigationBar.json

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,6 @@
6868
}
6969
}
7070
},
71-
"methods": {
72-
"set": [
73-
{
74-
"ts_only": true,
75-
"generics": [
76-
{
77-
"name": "T",
78-
"extends": "NativeObject",
79-
"default": "this"
80-
}
81-
],
82-
"parameters": [
83-
{
84-
"name": "properties",
85-
"type": "Properties<Omit<T, 'height'>>"
86-
}
87-
],
88-
"description": "Sets all key-value pairs in the properties object.",
89-
"returns": "this"
90-
}
91-
]
92-
},
9371
"links": [
9472
{
9573
"title": "Demonstrating various properties of the `NavigationBar`",

doc/api/Popover.json

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"const": true,
2424
"readonly": true,
2525
"ts_only": true,
26-
"type": "JSXAttributes<Omit<this, 'contentView'>> & {children?: JSXChildren<Widget>}"
26+
"type": "JSXAttributes<this> & {children?: JSXChildren<Widget>, contentView?: never}"
2727
},
2828
"contentView": {
2929
"const": true,
@@ -50,28 +50,6 @@
5050
}
5151
}
5252
},
53-
"methods": {
54-
"set": [
55-
{
56-
"ts_only": true,
57-
"generics": [
58-
{
59-
"name": "T",
60-
"extends": "NativeObject",
61-
"default": "this"
62-
}
63-
],
64-
"parameters": [
65-
{
66-
"name": "properties",
67-
"type": "Properties<Omit<T, 'contentView'>>"
68-
}
69-
],
70-
"description": "Sets all key-value pairs in the properties object as Popover properties.",
71-
"returns": "this"
72-
}
73-
]
74-
},
7553
"statics": {
7654
"methods": {
7755
"open": [

doc/api/StatusBar.json

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,6 @@
5656
"description": "Background color of the status bar. Should be used in conjunction with the `theme` property to keep the status bar icons legible."
5757
}
5858
},
59-
"methods": {
60-
"set": [
61-
{
62-
"ts_only": true,
63-
"generics": [
64-
{
65-
"name": "T",
66-
"extends": "NativeObject",
67-
"default": "this"
68-
}
69-
],
70-
"parameters": [
71-
{
72-
"name": "properties",
73-
"type": "Properties<Omit<T, 'height'>>"
74-
}
75-
],
76-
"description": "Sets all key-value pairs in the properties object.",
77-
"returns": "this"
78-
}
79-
]
80-
},
8159
"events": {
8260
"tap": {
8361
"description": "Fired when status bar is tapped.",

doc/api/TabFolder.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"selection": {
9696
"description": "The `Tap` selected by the user.",
9797
"type": "Tab",
98-
"ts_type": "Target extends TabFolder ? Target['selection'] : Tab"
98+
"ts_type": "Target extends TabFolder<any> ? Target['selection'] : Tab"
9999
}
100100
}
101101
},
@@ -105,7 +105,7 @@
105105
"selection": {
106106
"description": "The current value of the `selection` property.",
107107
"type": "Tab",
108-
"ts_type": "Target extends TabFolder ? Target['selection'] : Tab"
108+
"ts_type": "Target extends TabFolder<any> ? Target['selection'] : Tab"
109109
},
110110
"offset": {
111111
"description": "Number of pixels the current tab has scrolled horizontally.",

doc/api/Video.json

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,7 @@
9696
}
9797
],
9898
"description": "Starts playing the video, *[state](#state)* changes to `play`. Has no effect unless the current state is either `pause` or `ready`."
99-
},
100-
"set": [
101-
{
102-
"ts_only": true,
103-
"generics": [
104-
{
105-
"name": "T",
106-
"extends": "NativeObject",
107-
"default": "this"
108-
}
109-
],
110-
"parameters": [
111-
{
112-
"name": "properties",
113-
"type": "Properties<Omit<T, 'speed' | 'position' | 'duration' | 'state'>>"
114-
}
115-
],
116-
"description": "Sets all key-value pairs in the properties object as widget properties.\n\n**Important TypeScript note:** When called on `this` you may need to specify your custom type like this: `this.set<MyComponent>({propA: valueA});`",
117-
"returns": "this"
118-
}
119-
]
99+
}
120100
},
121101
"links": [
122102
{

0 commit comments

Comments
 (0)