🔎 Search Terms
I was thinking this code works like how the addEventLister or on behavior happens. Are there other less complex solutions?
🕗 Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKgFhACgJwPZgM5QLxQN4BQUxUAZgJbIbABc+RJjAhsgOYAMd1y5AdqwG4GjYi1YBGLsB78hjAL7CoGCAGNUvACZ1CIkmM5ReAVwC2AIwjI5eqGIBMdc6lQAbCE143iixsDiU2vS2dmwAzFIygkrMbAAsdCYWVt5QiooEmmquLNDqvNRQ0iAAwuZ0ADwA0lAQAB7AEFpYANYQIKiksAgo6BgAfAAUYGhgAHJMphB0VQA0UKrlUMOjGHTwSKsA2lUAugCUOP1QAG6o5JqH2MdnFwQExWWDAOQq+ZrP8yN9RwsaGG4IAA6VyoVgrPpAhz7fb3fKFYoAMWMvFUOCg1VqDSamla7U63U2fSG33Gk2mUDmUFJa0JvUwOwOv10JHIXQhZKmOFwrzUGg+hxZenhgJBYI5GChbHssIUBEUQA
💻 Code
type TheProps = {
first: {
arg0: string;
arg1: string;
}
second: {
arg0: number;
arg2: boolean;
}
third: {
arg3: string;
arg4: number;
}
}
declare const tryCb: <K extends keyof TheProps>(propName: K, cb: (props: TheProps[K]) => void) => void
tryCb('second', props => console.log(props.arg2)) // => no error (although this should also be an error)
const tryFunc = <K extends keyof TheProps>(propName: K, props: TheProps[K]) => {
if (propName == 'second') {
console.log(props.arg2) // => error here
}
}
🙁 Actual behavior
Property does not exist on selected type, but available via callback
🙂 Expected behavior
no error occurs same as using callback
Additional information about the issue
No response
🔎 Search Terms
I was thinking this code works like how the
addEventListeroronbehavior happens. Are there other less complex solutions?🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKgFhACgJwPZgM5QLxQN4BQUxUAZgJbIbABc+RJjAhsgOYAMd1y5AdqwG4GjYi1YBGLsB78hjAL7CoGCAGNUvACZ1CIkmM5ReAVwC2AIwjI5eqGIBMdc6lQAbCE143iixsDiU2vS2dmwAzFIygkrMbAAsdCYWVt5QiooEmmquLNDqvNRQ0iAAwuZ0ADwA0lAQAB7AEFpYANYQIKiksAgo6BgAfAAUYGhgAHJMphB0VQA0UKrlUMOjGHTwSKsA2lUAugCUOP1QAG6o5JqH2MdnFwQExWWDAOQq+ZrP8yN9RwsaGG4IAA6VyoVgrPpAhz7fb3fKFYoAMWMvFUOCg1VqDSamla7U63U2fSG33Gk2mUDmUFJa0JvUwOwOv10JHIXQhZKmOFwrzUGg+hxZenhgJBYI5GChbHssIUBEUQA
💻 Code
🙁 Actual behavior
Property does not exist on selected type, but available via callback
🙂 Expected behavior
no error occurs same as using callback
Additional information about the issue
No response