Skip to content

Computing best common type fails with weird error message #716

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
xirzec opened this issue Sep 20, 2014 · 2 comments
Closed

Computing best common type fails with weird error message #716

xirzec opened this issue Sep 20, 2014 · 2 comments
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@xirzec
Copy link
Member

xirzec commented Sep 20, 2014

interface IParserTest {
    name: string;
    input: string;
    result: any[];
    context?: any;
    error?: string;
}

var parserTests: IParserTest[] = [

    {
        name: "multipleBindingsWithSomeInitializers2",
        input: "textContent:b; innerHtml:e f;",
        result: [
            { destination: ["textContent"], source: ["b"] },
            { destination: ["innerHtml"], source: ["e"], initializer: 2 }
        ],
        context: { f: 2 }
    },
    {
        name: "bindingWithNumberLiterals",
        input: 'foo[1].baz:a.b[3]',
        result: [
            { destination: ["foo", 1, "baz"], source: ["a", "b", 3] }
        ]
    },
    {
        name: "errorBinding1",
        input: "textContent:b:c",
        error: "Invalid binding:'textContent:b:c'. Expected to be '<destProp>:<sourceProp>;'. Unexpected token: colon, expected one of: identifier, semicolon, eof, at offset 13"
    },
    {
        name: "errorBinding2",
        input: "textContent:b c: innerHtml: d e",
        error: "Invalid binding:'textContent:b c: innerHtml: d e'. Expected to be '<destProp>:<sourceProp>;'. Unexpected token: colon, expected one of: identifier, semicolon, eof, at offset 14",
        context: { c: 1, e: 3 }
    }
];

Gives the following error:

Cannot convert '{}[]' to 'IParserTest[]':
    Types of property 'pop' of types '{}[]' and 'IParserTest[]' are incompatible:
        Call signatures of types '() => {}' and '() => IParserTest' are incompatible:
            Type '{}' is missing property 'name' from type 'IParserTest'.
@RyanCavanaugh RyanCavanaugh added Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript labels Sep 22, 2014
@RyanCavanaugh
Copy link
Member

It is factual that the type of the array is {}[] -- no one element is a supertype of the rest, and there are members that don't have the required result field.

This is sort of the best we can do given the type algorithms we have. There's no obvious algorithm that generates a human-friendly error.

@xirzec
Copy link
Member Author

xirzec commented Sep 22, 2014

Somehow I didn't notice that result wasn't on all of them. I may have been staring at code too long this weekend. 🎢

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants