question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch to variadic generics for property and tuple

See original GitHub issue

Recent addition of “Extracting and spreading parameter lists with tuples” in TypeScript - https://blogs.msdn.microsoft.com/typescript/2018/07/12/announcing-typescript-3-0-rc/

It might be used to simplify multiple prebuild scripts.

Unfortunately it might impact the signatures provided for fc.property as rest parameters have to be at the end.

// OK
function call<TS extends any[], R>(fn: (...args: TS) => R, ...args: TS): R {
    return fn(...args);
}
// Not OK
function call2<TS extends any[], R>(...args: TS, fn: (...args: TS) => R): R {
    return fn(...args);
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
nth-commitcommented, Aug 25, 2020

You can replicate the existing API with the new variadic tuple feature in TS 4.0.

(approximated the existing types, Property and Arbitrary)

type Property<T> = {}

type Arbitrary<T> = {};

type UnwrapArbitrary<T extends Arbitrary<any>> = T extends Arbitrary<infer U> ? U : never;

type UnwrapArbitraries<T extends Array<Arbitrary<unknown>>> = { [P in keyof T]: UnwrapArbitrary<T[P]> };

type PropertyFunction<T extends Array<Arbitrary<unknown>>> = (...args: UnwrapArbitraries<T>) => (boolean | void);

declare function property<T extends Array<Arbitrary<unknown>>>(...args: [...T, PropertyFunction<T>]): Property<UnwrapArbitraries<T>>;

// Examples:

declare const arb0: Arbitrary<number>;
const p0: Property<[number]> = property(arb0, (x0) => {
  const _x0: number = x0;
  return true;
});

declare const arb1: Arbitrary<string>;
const p1: Property<[number, string]> = property(arb0, arb1, (x0, x1) => {
  const _x0: number = x0;
  const _x1: string = x1;
  return true;
});

declare const arb2: Arbitrary<{ foo: string }>;
const p2: Property<[number, string, { foo: string }]> = property(arb0, arb1, arb2, (x0, x1, x2) => {
  const _x0: number = x0;
  const _x1: string = x1;
  const _x2: { foo: string } = x2;
  return true;
});
1reaction
dubzzzcommented, Jul 16, 2018

In order to use this new TypeScript feature for fast-check code and get rid of all the unnecessary prebuild scripts, I see two potential alternatives for the signature of property:

  • fc.property([arb1, arb2,...], predicate) - not sure it is feasible
  • fc.property(predicate, arb1, arb2,...)

I’m not sure I will be able to keep today’s signature and use this feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 646 – Variadic Generics - Python Enhancement Proposals
In this PEP, we introduce TypeVarTuple , enabling parameterisation with an arbitrary number of types - that is, a variadic type variable, ...
Read more >
Three steps to Variadic Generics - Pitches - Swift Forums
variadic generics can be realized by the combination of "1. Operations for tuples" and "2. Variadic tuples". The former realizes operations for ...
Read more >
How do I create a new tuple from a variadic generic tuple in ...
First is that the compiler does not know that the array map() method will turn a tuple into a tuple, and it definitely...
Read more >
Allow variadic generics · Issue #193 · python/typing - GitHub
The idea is that you can have a generic class with a variable number of type variables, like typing.Tuple[] has. Here is a...
Read more >
TypeScript: Variadic Tuple Types Preview - fettblog.eu
A variadic tuple type is a tuple type that has the same properties — defined length and the type of each element is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found