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

typeArgument of JsxOpeningLikeElement ignored while checking JsxAttributes #22874

Closed
ajafff opened this issue Mar 26, 2018 · 4 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter Fixed A PR has been merged for this issue

Comments

@ajafff
Copy link
Contributor

ajafff commented Mar 26, 2018

TypeScript Version: 2.9.0-dev.20180328

Search Terms: jsx generic type arguments

Code

export {};

declare namespace JSX {
    interface Element {
        render(): Element | string | false;
    }
}

function SFC<T>(props: Record<string, T>) {
    return '';
}

/*1*/<SFC<string> prop={1}></SFC>;

Expected behavior:

Error on the prop attribute, because number is not assignable to string.

Actual behavior:

No error. Signature help incorrectly shows function SFC<number>(props: Record<string, number>): string

Playground Link:

Related Issues:

#22873

@mhegazy mhegazy added the Bug A bug in TypeScript label Mar 27, 2018
@mhegazy mhegazy added the Domain: JSX/TSX Relates to the JSX parser and emitter label Mar 27, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Mar 27, 2018
@weswigham
Copy link
Member

Attributes still get typechecked against any unless ElementAttributesProperty is specified with a interface ElementAttributesProperty { props: any; } declaration. (So even though you've said Record<string, string>, we ignore it and check against any because we failed to find the declaration.) We proooooooooooooobably don't need to look up props like this anymore, since we know we can always just use the the first argument of the ctor/function; but for now you can get the error you expect just by adding the required interface ElementAttributesProperty {} declaration into your JSX namespace.

@ajafff
Copy link
Contributor Author

ajafff commented Mar 28, 2018

@weswigham I actually have ElementAttributesProperty declared. I just omitted it for the report:

export {};

declare namespace JSX {
    interface IntrinsicElements {
        [elemName: string]: any;
    }

    interface Element {
        render(): Element | string | false;
    }

    interface ElementAttributesProperty {
        props: any;
    }
}

function SFC<T>(props: Record<string, T>) {
    return '';
}

<SFC<string> prop={1}></SFC>; // still no error

@weswigham
Copy link
Member

weswigham commented Mar 28, 2018

@ajafff We only look up a global JSX or a JSX under the factory function - your export {} makes it non-global, which means we don't find a JSX namespace at all.

@weswigham
Copy link
Member

Update: ElementAttributesProperty is now optional. We'll use the first parameter of the element's constructor/function for the type if it is not present.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 30, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants