From edf73f0806e70ff53469fc6b12b09b6ad7b5de69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Sat, 30 Sep 2023 05:46:40 +0200 Subject: [PATCH] [archive] Fix usage with TypeScript 4.8+ (#6779) * Fix template variable type * Remove additional typescript errors * Change files --- ...-673f775c-c439-46ef-93ae-7bd51076ce27.json | 7 ++ .../src/design-token/design-token.ts | 87 ++++++++++++++----- .../fast-foundation/src/di/di.ts | 2 +- .../fast-foundation/src/tabs/tabs.spec.ts | 2 +- 4 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 change/@microsoft-fast-foundation-673f775c-c439-46ef-93ae-7bd51076ce27.json diff --git a/change/@microsoft-fast-foundation-673f775c-c439-46ef-93ae-7bd51076ce27.json b/change/@microsoft-fast-foundation-673f775c-c439-46ef-93ae-7bd51076ce27.json new file mode 100644 index 00000000000..c7318137f3a --- /dev/null +++ b/change/@microsoft-fast-foundation-673f775c-c439-46ef-93ae-7bd51076ce27.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Fix typings for Typescript 4.8+", + "packageName": "@microsoft/fast-foundation", + "email": "fcollonval@gmail.com", + "dependentChangeType": "patch" +} diff --git a/packages/web-components/fast-foundation/src/design-token/design-token.ts b/packages/web-components/fast-foundation/src/design-token/design-token.ts index 0b60ff33655..00a03524c70 100644 --- a/packages/web-components/fast-foundation/src/design-token/design-token.ts +++ b/packages/web-components/fast-foundation/src/design-token/design-token.ts @@ -143,7 +143,7 @@ class DesignTokenImpl extends CSSDirective return [...this._appliedTo]; } - public static from( + public static from( nameOrConfig: string | DesignTokenConfiguration ): DesignTokenImpl { return new DesignTokenImpl({ @@ -157,9 +157,17 @@ class DesignTokenImpl extends CSSDirective }); } - public static isCSSDesignToken( - token: DesignToken | CSSDesignToken - ): token is CSSDesignToken { + public static isCSSDesignToken< + T extends + | string + | number + | boolean + | symbol + | any[] + | Uint8Array + | ({ createCSS?(): string } & Record) + | null + >(token: DesignToken | CSSDesignToken): token is CSSDesignToken { return typeof (token as CSSDesignToken).cssCustomProperty === "string"; } @@ -349,7 +357,7 @@ class CustomPropertyReflector { * A light wrapper around BindingObserver to handle value caching and * token notification */ -class DesignTokenBindingObserver { +class DesignTokenBindingObserver { public readonly dependencies = new Set>(); private observer: BindingObserver>; constructor( @@ -394,19 +402,24 @@ class DesignTokenBindingObserver { */ class Store { private values = new Map, any>(); - set(token: DesignTokenImpl, value: StaticDesignTokenValue) { + set( + token: DesignTokenImpl, + value: StaticDesignTokenValue + ) { if (this.values.get(token) !== value) { this.values.set(token, value); Observable.getNotifier(this).notify(token.id); } } - get(token: DesignTokenImpl): StaticDesignTokenValue | undefined { + get( + token: DesignTokenImpl + ): StaticDesignTokenValue | undefined { Observable.track(this, token.id); return this.values.get(token); } - delete(token: DesignTokenImpl) { + delete(token: DesignTokenImpl) { this.values.delete(token); } @@ -471,7 +484,7 @@ class DesignTokenNode implements Behavior, Subscriber { * @param start - The node to start looking for value assignment * @returns */ - public static findClosestAssignedNode( + public static findClosestAssignedNode( token: DesignTokenImpl, start: DesignTokenNode ): DesignTokenNode | null { @@ -581,7 +594,7 @@ class DesignTokenNode implements Behavior, Subscriber { * Checks if a token has been assigned an explicit value the node. * @param token - the token to check. */ - public has(token: DesignTokenImpl): boolean { + public has(token: DesignTokenImpl): boolean { return this.assignedValues.has(token); } @@ -590,7 +603,9 @@ class DesignTokenNode implements Behavior, Subscriber { * @param token - The token to retrieve the value for * @returns */ - public get(token: DesignTokenImpl): StaticDesignTokenValue | undefined { + public get( + token: DesignTokenImpl + ): StaticDesignTokenValue | undefined { const value = this.store.get(token); if (value !== undefined) { @@ -610,7 +625,9 @@ class DesignTokenNode implements Behavior, Subscriber { * @param token - The token to retrieve a raw value for * @returns */ - public getRaw(token: DesignTokenImpl): DesignTokenValue | undefined { + public getRaw( + token: DesignTokenImpl + ): DesignTokenValue | undefined { if (this.assignedValues.has(token)) { return this.assignedValues.get(token); } @@ -623,7 +640,10 @@ class DesignTokenNode implements Behavior, Subscriber { * @param token - The token to set * @param value - The value to set the token to */ - public set(token: DesignTokenImpl, value: DesignTokenValue): void { + public set( + token: DesignTokenImpl, + value: DesignTokenValue + ): void { if (DesignTokenImpl.isDerivedDesignTokenValue(this.assignedValues.get(token))) { this.tearDownBindingObserver(token); } @@ -641,7 +661,7 @@ class DesignTokenNode implements Behavior, Subscriber { * Deletes a token value for the node. * @param token - The token to delete the value for */ - public delete(token: DesignTokenImpl): void { + public delete(token: DesignTokenImpl): void { this.assignedValues.delete(token); this.tearDownBindingObserver(token); const upstream = this.getRaw(token); @@ -783,7 +803,10 @@ class DesignTokenNode implements Behavior, Subscriber { * @param token - The token to hydrate * @param value - The value to hydrate */ - public hydrate(token: DesignTokenImpl, value: DesignTokenValue) { + public hydrate( + token: DesignTokenImpl, + value: DesignTokenValue + ) { if (!this.has(token)) { const observer = this.bindingObservers.get(token); @@ -815,7 +838,7 @@ class DesignTokenNode implements Behavior, Subscriber { * @param token - The token to notify when the binding updates * @param source - The binding source */ - private setupBindingObserver( + private setupBindingObserver( token: DesignTokenImpl, source: DerivedDesignTokenValue ): DesignTokenBindingObserver { @@ -828,7 +851,9 @@ class DesignTokenNode implements Behavior, Subscriber { /** * Tear down a binding observer for a token. */ - private tearDownBindingObserver(token: DesignTokenImpl): boolean { + private tearDownBindingObserver( + token: DesignTokenImpl + ): boolean { if (this.bindingObservers.has(token)) { this.bindingObservers.get(token)!.disconnect(); this.bindingObservers.delete(token); @@ -845,13 +870,35 @@ function create( function create( nameOrConfig: string | DesignTokenConfiguration ): never; -function create(nameOrConfig: string): CSSDesignToken; -function create( +function create< + T extends + | string + | number + | boolean + | symbol + | any[] + | Uint8Array + | ({ createCSS?(): string } & Record) + | null +>(nameOrConfig: string): CSSDesignToken; +function create< + T extends + | string + | number + | boolean + | symbol + | any[] + | Uint8Array + | ({ createCSS?(): string } & Record) + | null +>( nameOrConfig: | Omit | (DesignTokenConfiguration & Record<"cssCustomPropertyName", string>) ): CSSDesignToken; -function create( +function create< + T extends string | number | boolean | symbol | {} | any[] | Uint8Array | null +>( nameOrConfig: DesignTokenConfiguration & Record<"cssCustomPropertyName", null> ): DesignToken; function create(nameOrConfig: string | DesignTokenConfiguration): any { diff --git a/packages/web-components/fast-foundation/src/di/di.ts b/packages/web-components/fast-foundation/src/di/di.ts index 5281f4b590a..19c2302f55e 100644 --- a/packages/web-components/fast-foundation/src/di/di.ts +++ b/packages/web-components/fast-foundation/src/di/di.ts @@ -1721,7 +1721,7 @@ export class ContainerImpl implements Container { } } - throw new Error(`Unable to resolve key: ${key}`); + throw new Error(`Unable to resolve key: ${String(key)}`); } public getAll( diff --git a/packages/web-components/fast-foundation/src/tabs/tabs.spec.ts b/packages/web-components/fast-foundation/src/tabs/tabs.spec.ts index dcd903f75f5..33bd182c58a 100644 --- a/packages/web-components/fast-foundation/src/tabs/tabs.spec.ts +++ b/packages/web-components/fast-foundation/src/tabs/tabs.spec.ts @@ -42,7 +42,7 @@ async function setup() { const [tabPanel1, tabPanel2, tabPanel3] = Array.from( element.querySelectorAll("fast-tab-panel") ); - const [tab1, tab2, tab3] = Array.from(element.querySelectorAll("fast-tab")); + const [tab1, tab2, tab3] = Array.from(element.querySelectorAll("fast-tab")); return { element,