TypeScript Record inferred typing doesn't recognize property

In our code we made a generic Dictionary and NumericDictionary, before we knew about the Record built in type.  We switched to using the built in, but then WebStorm now has a hard time inferring types for properties on the interfaces.  Below is sample code explaining the issue.  I would greatly appreciate if someone can explain why this is different or if this is a bug.  Thanks, and let me know if anything else is needed!

interface Dictionary<T> {
[index: string]: T
}

interface A {
modifier: string,
// 5 other properties
}

interface B {
modifier: string,
// 10 other properties
}

type aLookup = Record<string, A>;
type bLookup = Dictionary<B>;


function foobar(al: aLookup, bl: bLookup): void {
let aRecord = al['foo']; // aRecord inferred it is interface A
let am = aRecord.modifier; // .modifier doesn't understand where it is from, it shows all available modifier properties

let aRecordTyped: A = al['foo']; // aRecord is explicitly interface A
let tam = aRecordTyped.modifier; // .modifier knows it comes from the A interface

let bRecord = bl['foo']; // bRecord inferred it is interface B
let bm = bRecord.modifier; // .modifier knows it comes from the B interface
}
2 comments

Thanks for the response and creating the ticket.  Love the product.

0

Please sign in to leave a comment.