Closed
Description
🔎 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
💻 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
Metadata
Metadata
Assignees
Labels
No labels