microsoft/TypeScript

TS not indicating type missmatches

glazar opened this issue · 2 comments

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Code

interface Input {
  text?: string;
}

const test = (input: Input): string => {
  return "";
};

test("test");

Expected behavior:
Type mismatch indicated.
It works if I make the Input Interface text member non-optional.
Actual behavior:
No type mismatch indicated.
It works if I make the Input Interface text member non-optional.

It's because string is assignable to {}

const a:{} = "test"

Hence it is assignable to:

const a: { text?: string } = "test"

You might be interested in #12501 #1809

Duplicate #9841, etc.

Which search terms did you use before logging this? We're trying to reduce duplicates/questions and are curious what people are searching (and why they're not finding the existing issues) when logging bugs. Thanks!