Skip to content

Commit

Permalink
Support top-level await - fixes #1 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Sep 5, 2018
1 parent 0bc1413 commit a2f315c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions readme.md
Expand Up @@ -61,6 +61,18 @@ If we don't change the test file and we run the `tsd-check` command again, the t

<img src="screenshot.png" width="1330">

### Top-level `await`

If your method returns a `Promise`, you can use top-level `await` to resolve the value instead of wrapping it in an `async` [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).

```ts
import {expectType} from 'tsd-check';
import concat from '.';

expectType<Promise<string>>(concat('foo', 'bar'));

expectType<string>(await concat('foo', 'bar'));
```


## Assertions
Expand Down
7 changes: 6 additions & 1 deletion source/lib/compiler.ts
Expand Up @@ -2,6 +2,11 @@ import * as path from 'path';
import {createProgram, getPreEmitDiagnostics, ScriptTarget, ModuleResolutionKind, flattenDiagnosticMessageText} from 'typescript';
import {Diagnostic, Context} from './interfaces';

// List of diagnostic codes that should be ignored
const ignoredDiagnostics = new Set<number>([
1308 // Support top-level `await`
]);

const loadConfig = () => {
return {
moduleResolution: ModuleResolutionKind.NodeJs,
Expand All @@ -28,7 +33,7 @@ export const getDiagnostics = (context: Context): Diagnostic[] => {
const result: Diagnostic[] = [];

for (const diagnostic of diagnostics) {
if (!diagnostic.file) {
if (!diagnostic.file || ignoredDiagnostics.has(diagnostic.code)) {
continue;
}

Expand Down

0 comments on commit a2f315c

Please sign in to comment.