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 in jsxFactory #49237

Open
levvij opened this issue May 25, 2022 · 2 comments
Open

this in jsxFactory #49237

levvij opened this issue May 25, 2022 · 2 comments
Labels
Bug
Milestone

Comments

@levvij
Copy link

@levvij levvij commented May 25, 2022

Bug Report

I would like to create my own JSX-Factory which references this, for example this.createElement.

🔎 Search Terms

Custom JSX factory, this in jsx factory

🕗 Version & Regression Information

Tested on Version 4.7.2 and Version 4.8.0-dev.20220524 (@next).

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSX

⏄1�7 Playground Link

Sadly, playground does not support the jsxFactory tsconfig field, thus this can't be shown in playground.

💻 Code

{
    "compilerOptions": {
        "jsx": "react",
        "jsxFactory": "this.customCreateElement"
    }
}
class ExampleComponent {
    render() {
        return <app-example>
            <app-child></app-child>
        </app-example>;
    }

    customCreateElement(tagName: string, attributes: { [name: string]: any }, ...children: []) {
        // ... create something in the dom or whatever
    }
}

🙁 Actual behavior

TypeScripts emits the correct code with the this references (this.customCreateElement("app-example", null, this.customCreateElement("app-child", null));), but still throws an error:

index.tsx:3:17 - error TS2304: Cannot find name 'this'.
3         return <app-example>
                  ~~~~~~~~~~~

index.tsx:4:14 - error TS2304: Cannot find name 'this'.
4             <app-child></app-child>
               ~~~~~~~~~

Found 2 errors in the same file, starting at: index.tsx:3

🙂 Expected behavior

The output stays the same - but there is no error message.

@RyanCavanaugh RyanCavanaugh added the Bug label Jun 1, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 1, 2022
@RyanCavanaugh
Copy link
Member

@RyanCavanaugh RyanCavanaugh commented Jun 1, 2022

We'd take a fix for this if it's simple -- if not, I think this is "too bad" unless there's a stronger reason to add support for it.

@levvij
Copy link
Author

@levvij levvij commented Jun 1, 2022

I'd love to contribute myself, is there a starting point / do you know somewhere where I should start digging. I've already checked out the code and got it running!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug
Projects
None yet
Development

No branches or pull requests

2 participants