Properly test for valid type with dictionary
Merge pull request #4094 from wmtan/FixCheckForValidType

Fix check for valid type with dictionary