-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup downleveled types for typescript@4.2 and above
- Loading branch information
Showing
14 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as Sdk from '@aeternity/aepp-sdk'; | ||
|
||
console.log('Sdk', Sdk); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "typescript-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "main.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@aeternity/aepp-sdk": "file:../../.." | ||
}, | ||
"devDependencies": { | ||
"typescript": "4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# revisit --ignore-scripts after solving https://github.com/npm/cli/issues/4202 | ||
sed -i '' 's/"prepare"/"rem-prepare"/g' ../../../package.json | ||
|
||
for i in {9..1} | ||
do | ||
echo "Try typescript@4.$i" | ||
npm i "typescript@4.$i" -D --no-audit | ||
npx tsc | ||
done | ||
|
||
sed -i '' 's/"rem-prepare"/"prepare"/g' ../../../package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"target": "es2016", | ||
"moduleResolution": "node", | ||
"noEmit": true, | ||
"typeRoots": [ | ||
"./node_modules/@types", | ||
"../../../src/typings" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* required for TS\@4.4 and below | ||
* copied from https://github.com/microsoft/TypeScript/blob/f6628a4573cd37c26912f78de3d08cd1dbf687a5/lib/lib.es5.d.ts#L1530-L1539 | ||
* Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to | ||
* `never`. This emulates the behavior of `await`. | ||
*/ | ||
type Awaited<T> = | ||
// special case for `null | undefined` when not in `--strictNullChecks` mode | ||
T extends null | undefined ? T : | ||
// `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped | ||
T extends object & { then: (onfulfilled: infer F, ...args: infer _) => any } ? | ||
// if the argument to `then` is callable, extracts the first argument | ||
F extends ((value: infer V, ...args: infer _2) => any) ? | ||
Awaited<V> : // recursively unwrap the value | ||
never : // the argument to `then` was not callable | ||
T; // non-object or non-thenable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { copyFileSync, appendFileSync } from 'fs'; | ||
import { spawnSync } from 'child_process'; | ||
|
||
const run = (...args) => { | ||
const { error } = spawnSync('npx', args, { stdio: 'inherit', shell: true }); | ||
if (error) throw error; | ||
}; | ||
|
||
console.log('Generating types for typescript@4.2'); | ||
run('downlevel-dts', 'es', 'types-legacy/ts4.2', '--to=4.2'); | ||
copyFileSync('tooling/downlevel/globals-ts4.2.d.ts', 'types-legacy/ts4.2/globals.d.ts'); | ||
appendFileSync('types-legacy/ts4.2/index.d.ts', 'import \'./globals\';\n'); | ||
|
||
console.log('Generating types for typescript@4.5'); | ||
run('downlevel-dts', 'es', 'types-legacy/ts4.5', '--to=4.5'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": [ | ||
"test/**/*" | ||
"src/**/*", | ||
"test/**/*", | ||
"tooling/**/*" | ||
] | ||
} |