Last active
January 18, 2017 05:50
-
-
Save pablonete/377561e4762b1c5b0cc19fae164b6c94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sources = { | |
repo: { | |
title: "hola", | |
count: 3, | |
}, | |
editing: { | |
isDirty: false, | |
}, | |
} | |
type Sources = typeof sources; | |
function deepCompare<KSource extends keyof Sources, KName extends keyof Sources[KSource], T>( | |
key: KSource, | |
name: KName, | |
value: Sources[KSource][KName], | |
) { | |
return sources[key][name] === value; | |
} | |
// This should return a type error: "3 is not a string" | |
deepCompare("repo", "title", 3); | |
// But I'm getting "title" is not assignable to type 'never' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting the correct error. Saying "Argument of type '3' is not assignable to parameter of type 'string'".
Can it be related to the version of Typescript? I am using the 2.1 version from Typescript for Visual Studio.