Skip to content

Instantly share code, notes, and snippets.

@siassaj
Last active January 13, 2020 03:25
Show Gist options
  • Select an option

  • Save siassaj/884173d0256a534bccca8a87f667841e to your computer and use it in GitHub Desktop.

Select an option

Save siassaj/884173d0256a534bccca8a87f667841e to your computer and use it in GitHub Desktop.
// everything works totally correctly with this version
export function test<
P extends Props
>(input: unknown, innerCodec: TypeC<P>) {
return innerCodec.is(input) // no errors
}
// no errors within this function, but where the function is called such as
//
// test({}, someCodec)
// type { [x: string]: any } is missing the following properties from type '{ id: number; completed_at: string | null; }': id, completed_at [2345]
export function test<
P extends Props,
InnerCodec extends TypeC<P>, // <- use a named type to make it easier to read
>(input: unknown, innerCodec: InnerCodec) {
return innerCodec.is(input)
}
// no errors within this function, but where the function is called such as
//
// test({}, someCodec)
// type { [x: string]: any } is missing the following properties from type '{ id: number; completed_at: string | null; }': id, completed_at [2345]
export function test<
P extends Props,
InnerCodec extends TypeC<P> = TypeC<P>, // <- use a named type to make it easier to read
>(input: unknown, innerCodec: InnerCodec) {
return innerCodec.is(input)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment