From a2f315c8c68265e167b611e0215e57f761d29489 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Wed, 5 Sep 2018 21:00:31 +0200 Subject: [PATCH] Support top-level await - fixes #1 (#4) --- readme.md | 12 ++++++++++++ source/lib/compiler.ts | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 74362cc6..fe249e30 100644 --- a/readme.md +++ b/readme.md @@ -61,6 +61,18 @@ If we don't change the test file and we run the `tsd-check` command again, the t +### 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>(concat('foo', 'bar')); + +expectType(await concat('foo', 'bar')); +``` ## Assertions diff --git a/source/lib/compiler.ts b/source/lib/compiler.ts index d3779f22..57c23af9 100644 --- a/source/lib/compiler.ts +++ b/source/lib/compiler.ts @@ -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([ + 1308 // Support top-level `await` +]); + const loadConfig = () => { return { moduleResolution: ModuleResolutionKind.NodeJs, @@ -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; }