Skip to content

Commit e25da34

Browse files
authored
Merge pull request #10761 from marmelab/ts-5-8
[Chore] Upgrade TypeScript to v5.8
2 parents 5bf9230 + 986a3f2 commit e25da34

File tree

18 files changed

+99
-62
lines changed

18 files changed

+99
-62
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"storybook": "^8.6.11",
8282
"ts-jest": "^29.1.0",
8383
"tsx": "^4.19.3",
84-
"typescript": "^5.1.3",
84+
"typescript": "^5.8.3",
8585
"typescript-eslint": "^8.28.0",
8686
"whatwg-fetch": "^3.0.0"
8787
},

packages/ra-core/src/dataProvider/HttpError.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class HttpError extends Error {
2-
constructor(
3-
public readonly message,
4-
public readonly status,
5-
public readonly body: any = null
6-
) {
2+
status;
3+
body;
4+
constructor(message, status, body: any = null) {
75
super(message);
6+
this.status = status;
7+
this.body = body;
88
Object.setPrototypeOf(this, HttpError.prototype);
99
this.name = this.constructor.name;
1010
if (typeof Error.captureStackTrace === 'function') {

packages/ra-core/src/i18n/useTranslatable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const useTranslatable = (
3030
const context = useMemo<TranslatableContextValue>(
3131
() => ({
3232
locales,
33-
selectedLocale,
33+
selectedLocale: selectedLocale || 'en',
3434
selectLocale: setSelectedLocale,
3535
getRecordForLocale,
3636
}),

packages/ra-core/src/inference/InferredElement.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { createElement } from 'react';
22
import { InferredType } from './types';
33

44
class InferredElement {
5-
constructor(
6-
private type?: InferredType,
7-
private props?: any,
8-
private children?: any
9-
) {
5+
type?: InferredType;
6+
props?: any;
7+
children?: any;
8+
9+
constructor(type?: InferredType, props?: any, children?: any) {
1010
this.type = type;
1111
this.props = props;
1212
this.children = children;

packages/ra-core/src/inference/assertions.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,45 @@ export const isHtml = (value: any) => !value || HtmlRegexp.test(value);
2424
export const valuesAreHtml = (values: any[]) => values.every(isHtml);
2525

2626
const UrlRegexp = /http(s*):\/\/.*/i;
27-
export const isUrl = (value: any) => !value || UrlRegexp.test(value);
27+
export const isUrl = (value: any): value is string =>
28+
!value || UrlRegexp.test(value);
2829
export const valuesAreUrl = (values: any[]) => values.every(isUrl);
2930

3031
const ImageUrlRegexp =
31-
/http(s*):\/\/.*\.(jpeg|jpg|jfif|pjpeg|pjp|png|svg|gif|webp|apng|bmp|ico|cur|tif|tiff)/i;
32-
export const isImageUrl = (value: any) => !value || ImageUrlRegexp.test(value);
32+
/^http(s*):\/\/.*\.(jpeg|jpg|jfif|pjpeg|pjp|png|svg|gif|webp|apng|bmp|ico|cur|tif|tiff)/i;
33+
export const isImageUrl = (value: any): value is string =>
34+
!value || ImageUrlRegexp.test(value);
3335
export const valuesAreImageUrl = (values: any[]) => values.every(isImageUrl);
3436

3537
// This is a very simple regex to find emails
3638
// It is NOT meant to validate emails as the spec is way more complicated but is
3739
// enough for our inference needs
3840
const EmailRegexp = /@{1}/;
39-
export const isEmail = (value: any) => !value || EmailRegexp.test(value);
41+
export const isEmail = (value: any): value is string =>
42+
!value || EmailRegexp.test(value);
4043
export const valuesAreEmail = (values: any[]) => values.every(isEmail);
4144

42-
export const isArray = (value: any) => Array.isArray(value);
43-
export const valuesAreArray = (values: any[]) => values.every(isArray);
45+
export const isArray = (value: any): value is Array<any> =>
46+
Array.isArray(value);
47+
export const valuesAreArray = (values: any[]): values is Array<any>[] =>
48+
values.every(isArray);
4449

45-
export const isDate = (value: any) => !value || value instanceof Date;
46-
export const valuesAreDate = (values: any[]) => values.every(isDate);
50+
export const isDate = (value: any): value is Date =>
51+
!value || value instanceof Date;
52+
export const valuesAreDate = (values: any[]): values is Date[] =>
53+
values.every(isDate);
4754

48-
export const isDateString = (value: any) =>
55+
export const isDateString = (value: any): value is string =>
4956
!value ||
5057
(typeof value === 'string' &&
5158
(isMatch(value, 'MM/dd/yyyy') ||
5259
isMatch(value, 'MM/dd/yy') ||
5360
isValid(parseISO(value))));
5461

55-
export const valuesAreDateString = (values: any[]) =>
62+
export const valuesAreDateString = (values: any[]): values is string[] =>
5663
values.every(isDateString);
5764

58-
export const isObject = (value: any) =>
65+
export const isObject = (value: any): value is object =>
5966
Object.prototype.toString.call(value) === '[object Object]';
60-
export const valuesAreObject = (values: any[]) => values.every(isObject);
67+
export const valuesAreObject = (values: any[]): values is Array<object> =>
68+
values.every(isObject);

packages/ra-core/src/inference/inferElementFromValues.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const hasType = (type, types) => typeof types[type] !== 'undefined';
7979
*/
8080
const inferElementFromValues = (
8181
name,
82-
values = [],
82+
values: any[] = [],
8383
types: InferredTypeMap = defaultTypes
8484
) => {
8585
if (name === 'id' && hasType('id', types)) {

packages/ra-core/src/inference/inferTypeFromValues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface InferredElementDescription {
5858
*/
5959
export const inferTypeFromValues = (
6060
name,
61-
values = []
61+
values: any[] = []
6262
): InferredElementDescription => {
6363
if (name === 'id') {
6464
return { type: 'id', props: { source: name } };

packages/ra-core/src/preferences/usePreference.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,22 @@ import { usePreferenceKey } from './PreferenceKeyContext';
1212
* // this is equivalent to
1313
* const [theme, setTheme] = useStore('my-app.theme', 'light');
1414
*/
15-
export const usePreference = <T = any>(key?: string, defaultValue?: T) => {
15+
function usePreference<T>(
16+
key: string,
17+
defaultValue: T
18+
): [T, (value: T | ((value: T) => void), defaultValue?: T) => void];
19+
function usePreference<T = undefined>(
20+
key: string,
21+
defaultValue?: T | undefined
22+
): [T | undefined, (value: T | ((value: T) => void), defaultValue?: T) => void];
23+
function usePreference(): [
24+
unknown,
25+
(
26+
value: unknown | ((value: unknown) => void),
27+
defaultValue?: unknown
28+
) => void,
29+
];
30+
function usePreference<T>(key = '', defaultValue = undefined) {
1631
const preferenceKey = usePreferenceKey();
1732
if (!preferenceKey) {
1833
throw new Error(
@@ -24,4 +39,6 @@ export const usePreference = <T = any>(key?: string, defaultValue?: T) => {
2439
preferenceKey && key ? `${preferenceKey}.${key}` : preferenceKey ?? key,
2540
defaultValue
2641
);
27-
};
42+
}
43+
44+
export { usePreference };

packages/ra-core/src/preferences/usePreferenceInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { usePreference } from './usePreference';
1818
* );
1919
* }
2020
*/
21-
export const usePreferenceInput = (key?: string, defaultValue?: any) => {
21+
export const usePreferenceInput = (key: string, defaultValue?: any) => {
2222
const [valueFromStore, setValueFromStore] = usePreference(
2323
key,
2424
defaultValue

packages/ra-core/src/routing/useRestoreScrollPosition.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ export const useRestoreScrollPosition = (
6262
* );
6363
* };
6464
*/
65-
export const useTrackScrollPosition = (storeKey: string, debounceMs = 250) => {
66-
const [position, setPosition] = useStore(storeKey);
65+
export const useTrackScrollPosition = (
66+
storeKey: string,
67+
debounceMs: number = 250
68+
): [number | undefined, (value: number | undefined) => void] => {
69+
const [position, setPosition] = useStore<number | undefined>(storeKey);
6770

6871
useEffect(() => {
6972
if (typeof window === 'undefined') {

0 commit comments

Comments
 (0)