Skip to content

Commit

Permalink
add downlevel semantics to README (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandersn authored Feb 18, 2020
1 parent dc39688 commit b811012
Showing 1 changed file with 85 additions and 8 deletions.
93 changes: 85 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Less = Pick<T, Exclude<keyof T, K>>;
`Omit` has had non-builtin implementations since Typescript 2.2, but
became built-in in Typescript 3.5.

#### Semantics

`Omit` is a type alias, so the downlevel should behave exactly the same.

### Accessors (3.6)

Typescript prevented accessors from being in .d.ts files until
Expand All @@ -58,11 +62,17 @@ declare class C {
}
```

#### Semantics

The properties emitted downlevel can be overridden in more cases than
the original accessors, so the downlevel d.ts will be less strict. See
[the Typescript 3.7 release
notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier)
for more detail.

### Type-only import/export (3.8)

Typescript 3.8 supports type-only imports, but they are stricter than
Typescript's original imports, which let you import types or values.
So the downlevel emit is quite simple:
The downlevel emit is quite simple:

```ts
import type { T } from 'x';
Expand All @@ -74,6 +84,31 @@ becomes
import { T } from "x";
```

#### Semantics

The downlevel d.ts will be less strict because a class will be
constructable:

```ts
declare class C {
}
export type { C };
```

becomes

```ts
declare class C {}
export { C };
```

and the latter allows construction:

```ts
import { C } from "x";
var c = new C();
```

### `#private` (3.8)

Typescript 3.8 supports the new ECMAScript-standard #private properties in
Expand All @@ -87,7 +122,6 @@ declare class C {
}
```

(This is the standard emit for _any_ class with a #private property.)
It becomes:

```ts
Expand All @@ -96,9 +130,46 @@ declare class C {
}
```

#### Semantics

The standard emit for _any_ class with a #private property just adds a
single `#private` line. Similarly, a class with a private property
adds only the name of the property, but not the type. The d.ts
includes only enough information for consumers to avoid interfering
with the private property:

```ts
class C {
#x = 1
private y = 2
}
```
emits
```ts
declare class C {
#private
private y
}
```
which then downlevels to
```ts
declare class C {
private "#private";
private y;
}
```
This is incorrect if your class already has a field named `"#private"`.
But you really shouldn't do this!
The downlevel d.ts incorrectly prevents consumers from creating a
private property themselves named `"#private"`. The consumers of the
d.ts **also** shouldn't do this.
### `export * from 'x'` (3.8)
Typescript 3.8 supports the new ECMAScript-standard `export * as namespace` syntax, which is just syntactic sugar for two import/export
Expand All @@ -115,14 +186,20 @@ import * as ns_1 from "x";
export { ns_1 as ns };
```
#### Semantics
The downlevel semantics should be exactly the same as the original.
## Target
All told, that means that downlevel-dts targets Typescript 3.4. In the
future the downlevel target may be configurable as Typescript 3.4
becomes less used.
Since the earliest downlevel feature is from Typescript 3.5,
downlevel-dts targets Typescript 3.4. In the future the downlevel
target may be configurable as Typescript 3.4 becomes less used.
Currently, Typescript 3.0 features like `unknown` are not
downlevelled, nor are there plans to support Typescript 2.x.
downlevelled, nor are there any other plans to support Typescript 2.x.
### Downlevel semantics
## Usage
Expand Down

0 comments on commit b811012

Please sign in to comment.