Skip to content

Instantly share code, notes, and snippets.

@garthk
Created June 27, 2017 01:57
Show Gist options
  • Save garthk/1824311d2cae52a67c7bc73f5c9abfe7 to your computer and use it in GitHub Desktop.
Save garthk/1824311d2cae52a67c7bc73f5c9abfe7 to your computer and use it in GitHub Desktop.
declaration-output-mapped-types

declaration-output-mapped-types

Demonstrates bug with declaration output of mapped types in TypeScript 2.3.4.

Usage:

  • npm install
  • npm run build
  • Observe invalid syntax in dist/index.d.ts, which needs but lacks quotes around the keys in the declaration of scopes:
export declare const scopes: {
    noun:verb: "noun:verb";
    verb:adjective: "verb:adjective";
    noun: "noun";
};
export declare type Scope = keyof typeof scopes;
function strEnum<T extends string>(strings: Array<T>): {[K in T]: K} {
return strings.reduce((res, key) => {
res[key] = key;
return res;
}, Object.create(null));
}
export const scopes = strEnum([
'noun:verb',
'verb:adjective',
'noun'
]);
export type Scope = keyof typeof scopes;
{
"name": "declaration-output-mapped-types",
"version": "1.0.0",
"description": "Demonstrates bug with declaration output of mapped types",
"main": "dist/index.js",
"files": [
"*.json",
"*.md",
"dist"
],
"scripts": {
"build": "tsc"
},
"keywords": ["typescript", "bug"],
"author": "Garth Kidd <[email protected]>",
"license": "ISC",
"devDependencies": {
"typescript": "^2.3.4"
}
}
{
"compilerOptions": {
"declaration": true,
"lib": [
"es2015"
],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"sourceMap": false,
"target": "es2015"
},
"include": [
"*.ts"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment