As jcalz mentioned in his answer you can in fact achieve this by using generics and the new conditional types feature that will be released with TypeScript 2.8.
If you are using an npm based project you can try it out locally by installing the latest nightly build like this (the -g can be left out if you want to only install it in a local project):
npm install -g typescript@next
The code would look like this:
// the parens around the conditional expression are optional
function myFunc<T1 extends 'one' | 'two', T2 extends (T1 extends 'one' ? 1 : 2)>(name: T1, data?: T2) {
// do what you want
}
// No errors
myFunc('one', 1);
myFunc('two', 2);
myFunc('two');
// All of these cause a compile error
myFunc('one', 2);
myFunc('two', 1);
myFunc('three');
myFunc('two', 'string')
myFunc('one', 3);
// the first invocation (i.e. myFunc('one', 1)) leads to this resolved type
function myFunc<"one", 1>(name: "one", data?: 1 | undefined): void