Typescript: Gracefully parse 'super' with type arguments

Created on 2 Sep 2016  路  6Comments  路  Source: microsoft/TypeScript

From test superWithTypeArgument3:

image

We can just parse and throw away the results. If we're certain that this could be a call, we should just parse as a super() invocation to avoid downstream errors.

Bug Error Messages good first issue help wanted

Most helpful comment

Just to clarify, sometimes we change the parser to accept things we know aren't legal so that the errors are easier to understand. For example, this is never legal:

public class Foo {

}

A naive parser would just say "Unexpected token 'class'" but instead we parse it anyway and then later issue a more helpful "Can't use that modifier here" error

All 6 comments

Just curious, why that would be needed? super for the derived class is a concrete type, so what would that type arguments in super mean?

+1 to @Igorbek 's comment, what's the intent here?

Sorry to be obtuse as well, but since the generics aren't required on the constructor, why would they be required on the super? The It would be like having to write this, which isn't logical:

class D extends C  {
    constructor<T>() {
        super<T>();
    }
}

The intent is that instead of letting new users grapple with parse errors, we should give the most helpful experience we can. The fact that we understand why this doesn't work isn't indicative that newer users will immediately pick up on it.

Just to clarify, sometimes we change the parser to accept things we know aren't legal so that the errors are easier to understand. For example, this is never legal:

public class Foo {

}

A naive parser would just say "Unexpected token 'class'" but instead we parse it anyway and then later issue a more helpful "Can't use that modifier here" error

Thanks for articulating. I could've probably been a little clearer on that. 馃槃

Was this page helpful?
0 / 5 - 0 ratings