Skip to content

Regression in types starting with 5.1 #59176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sag-tobias-frey opened this issue Jul 8, 2024 · 2 comments
Closed

Regression in types starting with 5.1 #59176

sag-tobias-frey opened this issue Jul 8, 2024 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@sag-tobias-frey
Copy link

sag-tobias-frey commented Jul 8, 2024

🔎 Search Terms

types regression not generic

🕗 Version & Regression Information

  • This is a type regression
  • This changed between versions 5.0 and 5.1
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about breaking changes

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.1.6#code/PQKhCgAIUgBATApgBwE6IMYEMAuj6QCqAzopAAYCiAHhgDYCuS5kaA9gG4CWSBARgE9IAFQHJEAZQyouyHJC4A7YnizwAdFBDBwiasjap5SelnSQcYsgBEuAMzsAeYZD15F8YpADWiAWztILEUBABoiV2p3Tx8-AKCQgD5IAF5IAAoAbyhIXIBtAAUFRREAXQAuSAKAbnAAX0gAMkhs3PyipSIKyEVEDkRUWobm1ra86kqVGUUAc27e-sH6gEo84VLa0AhoOCQ0TFx8IlILAAsyReIuNhL2bl5IQRErKRk5YpVENU1oHT0DIyQEx0MxkSziSAAeQAtlwcI5COEANKRaJeXz+QKEZJpApcDDeBHhWwORwY+KIyBIxKJWq6fSGYyYEHmcE2RAoApmHBcLB0Zw4lo5drFWKYsoAfkqwkKpVRiA8XnSSjsAyIqzlEsg1g5yC5Rl5-OxeTl0tl8sVkDYfAAVph5FqdZzuYbnLLkmaCht6nT-oygczQRYrJAAJISSx0RAAMQYigwPJuzgjAijxAKqDYyGI4WEKajEkQ8jcCpi4cjkiLyYrhZwNNSGXY2el+cQ6cz2eWqWSTr1Lr51dTlbrmzAWkgACUUOhSIocF5EHDzqggpAVEPIHY4wnriUc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QSi8OYtxHAeQRFiIkVInRsixqlEURWQSu4qLYXhI1cIjVVIWUTj6IAA

💻 Code

/**
 * @deprecated Use `Exclude` provided by TypeScript instead.
 */
export declare type Diff<T extends keyof any, U extends keyof any> = ({
    [P in T]: P;
} & {
    [P in U]: never;
} & {
    [x: string]: never;
})[T];
/**
 * @deprecated Use the version provided by TypeScript instead.
 */
export declare type Omit<U, K extends keyof U> = Pick<U, Diff<keyof U, K>>;

export declare type DeepPartial<T> = {
    [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends object ? DeepPartial<T[P]> : T[P];
};

export declare type IStyleFunction<TStylesProps, TStyleSet extends IStyleSet<TStyleSet>> = (props: TStylesProps) => DeepPartial<TStyleSet>;
/**
 * Represents either a style function that takes in style props and returns a partial styleset,
 * or a partial styleset object.
 * {@docCategory IStyleFunctionOrObject}
 */
export declare type IStyleFunctionOrObject<TStylesProps, TStyleSet extends IStyleSet<TStyleSet>> = IStyleFunction<TStylesProps, TStyleSet> | DeepPartial<TStyleSet>;

export interface IRawStyle {
    /**
     * Allow css variables, strings, objects. While we should have more strict typing
     * here, partners are broken in many unpredictable cases where typescript can't infer
     * the right typing. Loosening the typing to both allow for css variables and other things.
     */
    [key: string]: any;
    /**
     * Display name for the style.
     */
    displayName?: string;
    /**
     * @deprecated - The selectors wrapper is no longer required. You may add selectors as siblings to other
     * style properties, like most css-in-js libraries support.
     */
    selectors?: {
        [key: string]: IStyle;
    };
}

export declare type IStyleBase = IRawStyle | string | false | null | undefined;
/**
 * {@docCategory IStyleBaseArray}
 */
export interface IStyleBaseArray extends Array<IStyle> {
}
/**
 * IStyleObject extends a raw style objects, but allows selectors to be defined
 * under the selectors node.
 * @public
 * {@docCategory IStyle}
 */
export declare type IStyle = IStyleBase | IStyleBaseArray;

export declare type IStyleSet<TStyleSet extends IStyleSet<TStyleSet> = {
    [key: string]: any;
}> = {
    [P in keyof Omit<TStyleSet, 'subComponentStyles'>]: IStyle;
} & {
    subComponentStyles?: {
        [P in keyof TStyleSet['subComponentStyles']]: IStyleFunctionOrObject<any, any>;
    };
};

🙁 Actual behavior

Type 'IStyleSet' is not generic.
Type 'IStyleSet' is not generic.
Type alias 'IStyleSet' circularly references itself.
Type parameter 'TStyleSet' has a circular constraint.
Type 'IStyleSet' is not generic.
Type parameter 'P' has a circular constraint.
Type 'string' does not satisfy the constraint 'keyof TStyleSet'.
Type '"subComponentStyles"' cannot be used to index type 'TStyleSet'.

🙂 Expected behavior

No errors

Additional information about the issue

I'm using @fluentui/merge-styles with version 8.5.15. This ships with the provided types above. This worked before Typescript version 5.1. Commenting out the custom Omit fixes the issue. However, I cannot change the code and cannot upgrade to a newer version right now.

@RyanCavanaugh
Copy link
Member

export declare type IStyleSet<TStyleSet extends IStyleSet<TStyleSet> = {

Circular constraints like this never really fully worked in the first place and were always intended to be disallowed. See #55743 (comment)

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 9, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants