Skip to content

request: Turn off required properties check in TSX context #12016

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
vvakame opened this issue Nov 3, 2016 · 8 comments
Closed

request: Turn off required properties check in TSX context #12016

vvakame opened this issue Nov 3, 2016 · 8 comments

Comments

@vvakame
Copy link
Contributor

vvakame commented Nov 3, 2016

I want to turn off required properties check in TSX context with using skate.js http://skate.js.org/
And, I don't want to turn of type checking about properties.

cc/ @bradleyayers do you interested in this issue?

TypeScript Version: 2.0.6

Code

Reproduce code is here.
https://gist.github.com/vvakame/e7a230fa558763e225b58d57b459f64d

summary

declare global {
    namespace JSX {
        interface ElementAttributesProperty {
            '': any;
        }
    }
}
declare module "skatejs" {
  export class Component extends HTMLElement {
  }
}
const ComponentA = skate.define("x-component-a", class ComponentA extends skate.Component {
    myCounter = 0;

    ...
}

skate.define("x-main", class Main extends skate.Component {
    render(elem: this): JSX.Element {
        return (
            // tsc raise a lot of errors!
            // error TS2324: Property 'ATTRIBUTE_NODE' is missing in type 'ComponentA'.
            // error TS2324: Property 'outerHTML' is missing in type 'ComponentA'.
            // ...
            // but I want a type checking...
            <ComponentA myCounter={-3}></ComponentA>
        );
    }

    ...
});

other information.

from src/compiler/checker.ts

        /// e.g. "props" for React.d.ts,
        /// or 'undefined' if ElementAttributesProperty doesn't exist (which means all
        ///     non-intrinsic elements' attributes type is 'any'),
        /// or '' if it has 0 properties (which means every
        ///     non-intrinsic elements' attributes type is the element instance type)
        function getJsxElementPropertiesName() {

I want to change targetAttributesType && !sawSpreadedAny to something like... targetAttributesType && !sawSpreadedAny && !suppressRequiredPropertyCheck.

        function checkJsxOpeningLikeElement(node: JsxOpeningLikeElement) {

            ...

            // Check that all required properties have been provided. If an 'any'
            // was spreaded in, though, assume that it provided all required properties
            if (targetAttributesType && !sawSpreadedAny) {
                const targetProperties = getPropertiesOfType(targetAttributesType);
                for (let i = 0; i < targetProperties.length; i++) {
                    if (!(targetProperties[i].flags & SymbolFlags.Optional) &&
                        !nameTable[targetProperties[i].name]) {

                        error(node, Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
                    }
                }
            }

Expected behavior:

We can compile my code.

Actual behavior:

tsc raise a lot of errors.

@thorn0
Copy link

thorn0 commented Nov 3, 2016

Duplicate of #7004.

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Nov 3, 2016

@thorn0 Is #7004 still relevant given that we are now free to annotate class members as optional.

@thorn0
Copy link

thorn0 commented Nov 3, 2016

Yes, it's still relevant. It's exactly the same issue that is described here.

If I mark members as optional, I'll have to add null checks for them everywhere, even for methods. This will not do.

@vvakame
Copy link
Contributor Author

vvakame commented Nov 4, 2016

I missed that issue, thank you!

@aluanhaddad
Copy link
Contributor

@thorn0 Sorry, I am not very experienced with React/JSX. thanks for clarifying.

@thorn0
Copy link

thorn0 commented Nov 4, 2016

@aluanhaddad JSX is an abstract syntax without inherent semantics so there is no such thing as the right and only way to type-check it. TypeScript recognizes this fact by providing means to configure how type-checking happens. These means are quite flexible, but just a bit not enough for some use cases.

@aluanhaddad
Copy link
Contributor

@thorn0 I didn't mean to suggest there was a right way or a wrong way, I was suggesting there might be a way.

@thorn0
Copy link

thorn0 commented Nov 4, 2016

@aluanhaddad I didn't mean to argue. It was just a little background on this issue.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants