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

incorrect type inference with Array on function parameters #3303

Open
ZigGreen opened this issue Jan 30, 2017 · 0 comments
Open

incorrect type inference with Array on function parameters #3303

ZigGreen opened this issue Jan 30, 2017 · 0 comments
Labels
bug Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program) Typing: tuple

Comments

@ZigGreen
Copy link

type C = { c: 2 }
type TE = {a: 'b', c: C };
type T = {a: 'b'};

function f(x: Array<TE>) {}
function g(x: Array<T>) {
  x.push({a: 'b'})
}

const x = [{ a: 'b', c: {c: 2}}];
f(x);
g(x);
x.map(x => x.c.c);

output:

No errors!

Due to Array isn't subtype of Array there must be an error. But when you explicitly specify x's type, you get the appropriate error:

// ...
const x: Array<TE> = [{ a: 'b', c: {c: 2}}];
// ...

output:

10: const x: Array<TE> = [{ a: 'b', c: {c: 2}}];
                   ^ property `c`. Property not found in
6: function g(x: Array<T>) {
                       ^ object type
@goodmind goodmind added Typing: tuple bug Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program) labels Jun 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program) Typing: tuple
Projects
None yet
Development

No branches or pull requests

2 participants