microsoft / fast

The adaptive interface system for modern web experiences.
https://www.fast.design
Other
9.27k stars 595 forks source link

FAST with Angular throws multiple errors #6602

Closed rishitdshah closed 5 months ago

rishitdshah commented 1 year ago

I'm following the steps mentioned in the docs - https://www.fast.design/docs/integrations/angular/ I encounter errors like -

Error: node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2252:66 - error TS2344: Type 'T' does not satisfy the constraint 'string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null'. Type 'T' is not assignable to type '{ createCSS?(): string; } & Record<PropertyKey, any>'. Type 'T' is not assignable to type '{ createCSS?(): string; }'. 2252 declare function create(nameOrConfig: string): CSSDesignToken; ~ node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2252:25

Refer to the image below

image

Am I missing something?

hawkticehurst commented 1 year ago

I also just ran into this issue while trying to update our Angular sample extension for the Webview UI Toolkit for VS Code.

I'm still unsure what the cause of this problem is (i.e. what changed in Angular v15 to cause this bug) but was able to find a solution for the problem by manually updating the fast-foundation.d.ts file inside node_modules.

I've made a small reproduction of the issue for validation/convenience.

To summarize, however:

Inside node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.tson lines 2252, 2254, and 2256 are a handful of type declarations for the create function.

I got the same error messages as the screenshot above talking about how type 'T' is not assignable to the various types. At the bottom of the screenshot (and partially cut off) the TS compiler actually suggests the correct solution which is to extend type 'T' of the create function with the same set of types that the CSSDesignToken generic type extends.

The working solution I came up with is to replace lines 2252, 2254, and 2256 with the following:

declare function create<T extends string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null>(nameOrConfig: string): CSSDesignToken<T>;

declare function create<T extends string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null>(nameOrConfig: Omit<DesignTokenConfiguration, "cssCustomPropertyName"> | (DesignTokenConfiguration & Record<"cssCustomPropertyName", string>)): CSSDesignToken<T>;

declare function create<T extends string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null>(nameOrConfig: DesignTokenConfiguration & Record<"cssCustomPropertyName", null>): DesignToken<T>;

Obviously, manually updating the fast-foundation type declaration file inside node_modules is an unsustainable solution, so any work that can be done to update the generated type declarations within FAST would be greatly appreciated!

(Or for anyone who might have more insight into what changed about Angular v15 than I, maybe there is a way to change the configurations on the Angular side to make the current fast foundation type declaration file work???).

chrisdholt commented 1 year ago

What version of TS does this repro with?

hawkticehurst commented 1 year ago

~4.8.2 (and the old angular sample used 4.1.3)

chrisdholt commented 1 year ago

~4.8.2 (and the old angular sample used 4.1.3)

I'm pretty sure this is the culprit. TypeScript's versioning doesn't strictly follow semver and types are subject to breaking in between minor versions. I have a feeling that some version prior to v4.8.2 is incompatible with our current implementation somewhere. This is a tricky scenario as updating is likely to trigger breaking changes in folks who have not yet updated their TS versions. In the past we've held that we're okay if typings need to break in minor versions but we try to avoid it. I'll mark this for follow-up but I have a feeling that if you downgraded or force-resolved TS to something like 4.3.5 it would either "work" or break with other errors related to Angular's package.

hawkticehurst commented 1 year ago

Cool, that makes sense and is totally reasonable imo. I'll see if I can force-resolve TS to a previous version, but if that doesn't work I have the flexibility to downgrade and will just keep an eye on this issue in the long term

Thanks!

rishitdshah commented 1 year ago

What version of TS does this repro with?

Typescript: 4.8.2 Node: 16.14.2 Angular: 15

rishitdshah commented 1 year ago

image

Errors:

Error: node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2252:66 - error TS2344: Type 'T' does not satisfy the constraint 'string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null'. Type 'T' is not assignable to type '{ createCSS?(): string; } & Record<PropertyKey, any>'. Type 'T' is not assignable to type '{ createCSS?(): string; }'. 2252 declare function create(nameOrConfig: string): CSSDesignToken; ~ node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2252:25 2252 declare function create(nameOrConfig: string): CSSDesignToken; ~ This type parameter might need an extends { createCSS?(): string; } constraint. node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2252:25 2252 declare function create(nameOrConfig: string): CSSDesignToken; ~ This type parameter might need an extends { createCSS?(): string; } & Record<PropertyKey, any> constraint. node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2252:25 2252 declare function create(nameOrConfig: string): CSSDesignToken; ~ This type parameter might need an extends string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null constraint. Error: node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2254:186 - error TS2344: Type 'T' does not satisfy the constraint 'string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null'. Type 'T' is not assignable to type '{ createCSS?(): string; } & Record<PropertyKey, any>'. Type 'T' is not assignable to type '{ createCSS?(): string; }'. 2254 declare function create(nameOrConfig: Omit<DesignTokenConfiguration, "cssCustomPropertyName"> | (DesignTokenConfiguration & Record<"cssCustomPropertyName", string>)): CSSDesignToken; ~ node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2254:25 2254 declare function create(nameOrConfig: Omit<DesignTokenConfiguration, "cssCustomPropertyName"> | (DesignTokenConfiguration & Record<"cssCustomPropertyName", string>)): CSSDesignToken; ~ This type parameter might need an extends { createCSS?(): string; } constraint. node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2254:25 2254 declare function create(nameOrConfig: Omit<DesignTokenConfiguration, "cssCustomPropertyName"> | (DesignTokenConfiguration & Record<"cssCustomPropertyName", string>)): CSSDesignToken; ~ This type parameter might need an extends { createCSS?(): string; } & Record<PropertyKey, any> constraint. node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2254:25 2254 declare function create(nameOrConfig: Omit<DesignTokenConfiguration, "cssCustomPropertyName"> | (DesignTokenConfiguration & Record<"cssCustomPropertyName", string>)): CSSDesignToken; ~ This type parameter might need an extends string | number | boolean | symbol | any[] | Uint8Array | ({ createCSS?(): string; } & Record<PropertyKey, any>) | null constraint. Error: node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2256:121 - error TS2344: Type 'T' does not satisfy the constraint 'string | number | boolean | symbol | {} | any[] | Uint8Array | null'. Type 'T' is not assignable to type 'Uint8Array'. 2256 declare function create(nameOrConfig: DesignTokenConfiguration & Record<"cssCustomPropertyName", null>): DesignToken; ~ node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2256:25 2256 declare function create(nameOrConfig: DesignTokenConfiguration & Record<"cssCustomPropertyName", null>): DesignToken; ~ This type parameter might need an extends Uint8Array constraint. node_modules/@microsoft/fast-components/node_modules/@microsoft/fast-foundation/dist/fast-foundation.d.ts:2256:25 2256 declare function create(nameOrConfig: DesignTokenConfiguration & Record<"cssCustomPropertyName", null>): DesignToken; ~ This type parameter might need an extends string | number | boolean | symbol | {} | any[] | Uint8Array | null constraint.

pavangayakwad commented 1 year ago

Nothing works as per the documentation. I downgraded TS version to 4.3.5 and Angular 15+ errored me saying that it needs >4.8 TS version.

chrisdholt commented 1 year ago

Nothing works as per the documentation. I downgraded TS version to 4.3.5 and Angular 15+ errored me saying that it needs >4.8 TS version.

If you’d like to put together a repro on stackblitz I would be happy to confirm - my assumption is a dependency issue.

My asssumption is Angular 15+ expects TS > 4.8. My assumption is that there are breaking changes we need to address in 4.8. I don’t think this is a docs issue, I think it’s that TS makes breaking changes in minor versions and Angular is pegged at a higher version. Happy to look into upgrading but it may require breaks to types.

pavangayakwad commented 1 year ago

Following the documentation and running it locally with angular 15 will easily reproduce the issue.

f1am3d commented 1 year ago

Same for me.

usrrname commented 1 year ago

OP: You may have to pin your dependency at TS 4.7...

anna-rak commented 1 year ago

Hello! Are there any plans to fix this issue? I do not see it in the roadmap, and it is preventing us from using the newer Angular versions.. Thanks!

usrrname commented 1 year ago

Well, amateur wc-ist here but I have been looking into this and can update this thread on my journey :)

tagazok commented 1 year ago

Hi Is there a fix planed to solve this issue?

vnau commented 1 year ago

There is PR #6821 which should fix the issue.

Angular 15 can be used with TypeScript 4.9 and the SkipLibCheck option as a temporary workaround.

janechu commented 5 months ago

This issue looks a little outdated, we are in process to launch v2 of @microsoft/fast-element which includes many dependency updates which may solve this issue. Closing for now, please open an issue if you still see a problem after the v2 launch.