microsoft / microsoft/TypeScript

Type assertions using Exact, Subset, Superset

Open
#28,586 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

I have suffered several times with the limitations of casting like so:

res.json(<Foo>{foo:'bar'});

the above cast/assertion will work even if the anonymous object does not have all the fields in type Foo.
For example, this question I had: https://stackoverflow.com/questions/53328459/prevent-compilation-unless-all-fields-exist

This feature request is for something like this:

res.json(Exact<Foo>{foo:'bar'});
res.json(Subset<Foo>{foo:'bar'});
res.json(Superset<Foo>{foo:'bar'});

note this is similar to the existing construct Partial, as in Partial<T>, hopefully the above are self-explanatory. I am not sure if both Subset<> and Superset<> make sense, but one of them should.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed Exact, Subset, and Superset type-assertion syntax and compare it with the existing Partial construct. Define which semantics are required, including whether both Subset and Superset are needed; the issue names no files, tests, or entry points, so completion would require establishing the design and its validation criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.