Skip to content

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

Description

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/ Bradley Ayers (@bradleyayers) do you interested in this issue?

TypeScript Version: 2.0.6

Code

Reproduce code is here.
https://github.com/proxy/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.

Activity

  1. thorn0 commented on Nov 3, 2016

    @thorn0

    Duplicate of #7004.

  2. aluanhaddad commented on Nov 3, 2016

    @aluanhaddad
    Contributor

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

  3. thorn0 commented on Nov 3, 2016

    @thorn0

    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.

  4. vvakame commented on Nov 4, 2016

    @vvakame
    ContributorAuthor

    I missed that issue, thank you!

  5. aluanhaddad commented on Nov 4, 2016

    @aluanhaddad
    Contributor

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

  6. thorn0 commented on Nov 4, 2016

    @thorn0

    Aluan Haddad (@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.

  7. aluanhaddad commented on Nov 4, 2016

    @aluanhaddad
    Contributor

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

  8. thorn0 commented on Nov 4, 2016

    @thorn0

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

  9. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions