Repository: TypeScript
Issue: Future-proof non-aliasing/always-expanding of mapped/intersection/union/etc. types
Labels: Suggestion,Needs Proposal

<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker.

Please help us by doing the following steps before logging an issue:
  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues
  * Read the FAQ, especially the "Common Feature Requests" section: https://github.com/Microsoft/TypeScript/wiki/FAQ

-->

## Search Terms

<!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily -->

non-aliasing types

## Suggestion

<!-- A summary of what you'd like to see added or changed -->

I would like an "officially blessed" way to tell TS if it should give me a type alias, or give me an "expanded" type. (See examples)

Now that this issue has been fixed,
https://github.com/microsoft/TypeScript/issues/32824

the technique I've been using to force TS to not alias a type will break when I migrate to TS 3.6/3.7

## Use Cases

<!--
What do you want to use this for?
What shortcomings exist with current approaches?
-->

In some cases, seeing `Mapped1<T>/Intersected1<T>/Unioned1<T>` is better for a developer (see examples).

In other cases, seeing the full "expanded" type is better (see examples for `Mapped2<T>/Intersected2<T>/Unioned2<T>`)

## Examples

```ts
type Identity<T> = T;

type Mapped1<T> = { [k in keyof T]: [T[k], "mapped"] };
type Mapped2<T> = Identity<{ [k in keyof T]: [T[k], "mapped"] }>;

declare function foo1(): Mapped1<{ x: string, y: number }>;
declare function foo2(): Mapped2<{ x: string, y: number }>;

/*
Aliased, bad
const m1: Mapped1<{
    x: string;
    y: number;
}>
*/
const m1 = foo1();
/*
Non-aliased, good
const m2: {
    x: [string, "mapped"];
    y: [number, "mapped"];
}
*/
const m2 = foo2();

//==============================================================

type Intersected1<T> = T & { hi: string };
type Intersected2<T> = Identity<T & { hi: string }>;

declare function bar1(): Intersected1<{ x: string, y: number }>;
declare function bar2(): Intersected2<{ x: string, y: number }>;

/*
const i1: Intersected1<{
    x: string;
    y: number;
}>
*/
const i1 = bar1();
/*
const i2: {
    x: string;
    y: number;
} & {
    hi: string;
}
*/
const i2 = bar2();

//==============================================================

type Unioned1<T> = T | { hi: string };
type Unioned2<T> = Identity<T | { hi: string }>;

declare function baz1(): Unioned1<{ x: string, y: number }>;
declare function baz2(): Unioned2<{ x: string, y: number }>;

/*
const u1: Unioned1<{
    x: string;
    y: number;
}>
*/
const u1 = baz1();
/*
const u2: {
    hi: string;
} | {
    x: string;
    y: number;
}
*/
const u2 = baz2();
```
[Playground](http://www.typescriptlang.org/play/?ts=3.7-Beta&ssl=1&ssc=1&pln=74&pc=19#code/C4TwDgpgBAkgJhAdsAlqAPAFQHxQLxSYDcAUCaJFALICGYkcAjFrgQN5QDaA1lColG4QQAewBmhALoAuLph6SANFABEAWzoMVkqAF9SFaLXoQ4AJhb5YCZGhDoOPPgKGiJmGXIXL1m09r1sUhIEAGMAGxoAJ2gxAFdEUNQRATEREUYACgBKWWMGZg4AD1kAZ2Ao-gBzZRBZRDi1ACMIKMDSMMiYqHjE5NT0sxy8v3MHKBKocsrEGqg6qAbm1vayAHoAKhIAQXCUGlLTZSaaOBJQlPKoNUYRkyYHEihnibKK6tIX+frGlqjSXTYEgbNbnS7Aa6MKxpDI5UibEgAORSAFoaHsDkcoFV0mcLogrmozLI2E8XpNONNqj4NPdtJ8XgtOEs-jTRvSSLpgaD8YSzNDBnD1ms8KKxeKJZKpdKZbKpWRDLBkK1DklTMwcFZMFAAGRQDgACxQbxmVT0BnA0BgyqiquApgsmoI8CQqAw2r1huNU3es1WIQgEWisQSSRQKSgJyiWVySvttsD9oexRN1O+i1+K0BHUDXRDfXDAijQ1j1vjdod40mVNmtR+yza2fWW15EJQtzjKsT6seX2rvqqDOeCxZrQBQJBYIJbahBCjMfhLfBfGJ+rJz37pqH6dH-05urXXyNqdmAO5U6uKH5c+iJeCaxFcqfz5fcoVlqgAFVEIWe07CFAAA++pQMePqmua5Aft+v5jP+Lq2O6QEgWBNZmk2AZBt0vRhhGJwAF4xrIMEpD2KbgWmI6Zo2QSYXmPShv0kY0PhJbET+pFjORaF1hmDb+girZQHEHYkYgZHrq8FGnpJVENuO55CSJVgEQuJCCcucSrqSR7emhALITp5InoOsn1n8Z6Tkp17MaxcJAA)

## Checklist

My suggestion meets these guidelines:

* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [x] This wouldn't change the runtime behavior of existing JavaScript code
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).

## Related

https://github.com/microsoft/TypeScript/issues/32824#issuecomment-521127740

@weswigham brought up a different way to force TS to not alias a type.

I prefer my `Identity<T>` trick because it doesn't create a new "temporary" object type.