Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude<any,whatever> (another way of negated type #29317) #33318

Closed
5 tasks done
escKeyStroke opened this issue Sep 9, 2019 · 3 comments
Closed
5 tasks done

Exclude<any,whatever> (another way of negated type #29317) #33318

escKeyStroke opened this issue Sep 9, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@escKeyStroke
Copy link

Hi

Search Terms

Exclude<any
type subtraction
any but
all types except
Checked: #31579 #29317

Suggestion

type T00 = Exclude<any,whatever>

T00 should be composed of any (all) types, except those types that are assignable to whatever

Use Cases

I definded a bunch of functions according to the following interface:

interface ecafretni { (x:any, y:Q): any }

x literally takes any type, there's no possible narrowing down. Think of a general-purpose deep-copy function, for example. Q is some other interface I defined somewhere. Here's the use case: I had to change the order of the arguments of ecafretni to (y:Q, x:any) and I was wishing that TypeScript would point out all the (hundreds of) points where I was calling functions abiding by that interface, so that I woulnd't miss any. But it wouldn't because, of course, type Q is assignable to any and type any is assignable to Q.

So I came up with another type to use in the place of any: R = Exclude<any,Q>, and redefine ecafretni argument types as f(y:Q, x:R). But it's not working. It seems that R behaves the same way as any.

Examples

const f = function( x : Exclude<any,Number> ){};
const x:Number = 4;
const v = f(x); // TYPE MISMATCH !!!! (not caught by TypeScript)

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@MartinJohns
Copy link
Contributor

Duplicate of #29317.

@jack-williams
Copy link
Collaborator

Duplicate of #29188

@jack-williams jack-williams marked this as a duplicate of #29188 Sep 9, 2019
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 13, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants