Skip to content
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

this types in intrinsic class attributes not inferred correctly #21662

Open
weswigham opened this issue Feb 6, 2018 · 0 comments
Open

this types in intrinsic class attributes not inferred correctly #21662

weswigham opened this issue Feb 6, 2018 · 0 comments
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Milestone

Comments

@weswigham
Copy link
Member

Code

// @strict: true
// @jsx: preserve
namespace JSX {
    export interface Element {}
    export interface IntrinsicClassAttributes<TClass> {
        ref?: (ref: TClass) => void;
        acceptProps?: (props: this) => boolean;
        key: string;
    }
    export interface ElementClass extends Element {}
    export interface ElementAttributesProperty { props: {}; }
    export interface ElementChildrenAttribute { children: {}; }
    export interface IntrinsicAttributes {}
    export interface IntrinsicElements { [key: string]: Element }
}
class ElemClass<T extends {x: number}> implements JSX.ElementClass {
    constructor(public props: T) {}
}
const elem = <ElemClass x={12} y={24} key="elem" ref={me => void me.props.y} acceptProps={p => p.ref(null as any) || void p.key || void p.y} />

Expected behavior:
no errors

Actual behavior:

    const elem = <ElemClass x={12} y={24} key="elem" ref={me => void me.props.y} acceptProps={p => p.ref(null as any) || void p.key || void p.y} />
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ x: number; y: number; key: string; ref: (me: ElemClass<any>) => undefined; acceptProps: (p: IntrinsicAttributes & IntrinsicClassAttributes<ElemClass<any>> & any) => undefined; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>> & { x: number; y: number; key: string; ref: {}; acceptProps: {}; }'.
!!! error TS2322:   Type '{ x: number; y: number; key: string; ref: (me: ElemClass<any>) => undefined; acceptProps: (p: IntrinsicAttributes & IntrinsicClassAttributes<ElemClass<any>> & any) => undefined; }' is not assignable to type 'IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>>'.
!!! error TS2322:     Types of property 'acceptProps' are incompatible.
!!! error TS2322:       Type '(p: IntrinsicAttributes & IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>> & { x: number; y: number; key: string; ref: {}; acceptProps: {}; }) => undefined' is not assignable to type '((props: IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>>) => boolean) | undefined'.
!!! error TS2322:         Type '(p: IntrinsicAttributes & IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>> & { x: number; y: number; key: string; ref: {}; acceptProps: {}; }) => undefined' is not assignable to type '(props: IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>>) => boolean'.
!!! error TS2322:           Types of parameters 'p' and 'props' are incompatible.
!!! error TS2322:             Type 'IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>>' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>> & { x: number; y: number; key: string; ref: {}; acceptProps: {}; }'.
!!! error TS2322:               Type 'IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>>' is not assignable to type '{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }'.
!!! error TS2322:                 Property 'x' is missing in type 'IntrinsicClassAttributes<ElemClass<{ x: number; y: number; key: string; ref: {}; acceptProps: {}; }>>'.

Unlike I initially expected, there's only an issue with this types - this types are formulated from contextual types, so fixing this probably just requires tightening the new jsx inference code to instantiate the type with the correct this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Projects
Rolling Work Tracking
  
Not started
Development

No branches or pull requests

4 participants