Closed
Description
TypeScript Version:
Version 1.9.0-dev.20160617-1.0
Code
interface Foo {
prop?: string
[key: string]: string
}
{
"compilerOptions": {
"strictNullChecks": true
}
}
Expected behavior: No error. Wouldn't the fact that it's an index signature implicitly signal that it could also be undefined
?
Actual behavior:
index.ts(2,3): error TS2411: Property 'prop' of type 'string | undefined' is not assignable to string index type 'string'.
Edit: On the other side of the coin with this usage:
interface Foo {
[key: string]: string
}
const foo: Foo = {}
const bar = foo['test']
Should bar
be type of string | undefined
?