Skip to content

Instantly share code, notes, and snippets.

@warrenday
Created January 21, 2023 12:31
Show Gist options
  • Select an option

  • Save warrenday/37fed0fa3320b273ef18cbcaed0d8976 to your computer and use it in GitHub Desktop.

Select an option

Save warrenday/37fed0fa3320b273ef18cbcaed0d8976 to your computer and use it in GitHub Desktop.
function positionalProp<
N extends string, F extends boolean | string | number
>(name: N, fallback?: F): (
F extends false ?
string | number | false
: F extends string ? string : number
)
const x = positionalProp('foo', false) // string | number | false
const x2 = positionalProp('foo', 'hello') // string
const x3 = positionalProp('foo', 2) // number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment