-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve type testing for older versions of TypeScript (#254)
* Run types tests with multiple versions of TypeScript * Test older versions of TypeScript by separate @ts-expect-error tests * Remove old versions test from GitHub actions workflow * Add comment
- Loading branch information
1 parent
a03f141
commit 4f2d0af
Showing
13 changed files
with
367 additions
and
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src |
File renamed without changes.
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,48 @@ | ||
#!/usr/bin/env zx | ||
|
||
import fs from 'fs'; | ||
import 'zx/globals'; | ||
|
||
const VERSIONS = [ | ||
'next', | ||
'beta', | ||
'latest', | ||
'3.9.7', | ||
'3.8.3', | ||
'3.7.4', | ||
'3.6.3', | ||
'3.5.1', | ||
'3.4.4', | ||
'3.3.3', | ||
'3.2.1', | ||
|
||
// Attempting to test on 3.1.1 currently fails. I believe it is not a | ||
// fundamental incompability with the types, just some tsconfig.json changes | ||
// that are needed. Skipping for now | ||
// '3.1.1', | ||
]; | ||
|
||
const TYPE_TESTS_DIR = `${__dirname}/..`; | ||
|
||
// Ensure working directory is test directory | ||
cd(TYPE_TESTS_DIR); | ||
|
||
if (fs.existsSync(`${TYPE_TESTS_DIR}/package.json`)) { | ||
await $`rm package.json`; | ||
} | ||
|
||
await $`yarn init -sy`; | ||
|
||
for (const version of VERSIONS) { | ||
console.log(`--- Testing with TypeScript version ${version}`); | ||
await $`yarn add -s --no-progress typescript@${version}`; | ||
await $`yarn run tsc --strict --noEmit src/valid.ts`; | ||
|
||
// TypeScript versions >= 3.9.0 support [@ts-expect-error][0], which lets us | ||
// write tests for types that we expect to cause errors | ||
// | ||
// [0]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-ts-expect-error-comments | ||
if (version >= '3.9.0') { | ||
await $`yarn run tsc --strict --noEmit src/invalid.ts`; | ||
} | ||
} |
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,91 @@ | ||
///<reference path='../../../types/index.d.ts' /> | ||
|
||
import { | ||
Stripe, | ||
StripeElements, | ||
StripeCardElement, | ||
StripeIbanElement, | ||
StripePaymentElement, | ||
} from '@stripe/stripe-js'; | ||
|
||
declare const stripe: Stripe; | ||
declare const elements: StripeElements; | ||
declare const cardElement: StripeCardElement; | ||
declare const ibanElement: StripeIbanElement; | ||
declare const paymentElement: StripePaymentElement; | ||
|
||
elements.update({ | ||
// @ts-expect-error: `clientSecret` is not updatable | ||
clientSecret: 'pk_foo_secret_bar', | ||
}); | ||
|
||
elements.update({ | ||
// @ts-expect-error: `fonts` is not updatable | ||
fonts: [], | ||
}); | ||
|
||
paymentElement.on('change', (e) => { | ||
// @ts-expect-error: `error` is not present on PaymentElement "change" event. | ||
if (e.error) { | ||
} | ||
}); | ||
|
||
stripe | ||
.confirmPayment({elements, confirmParams: {return_url: ''}}) | ||
.then((res) => { | ||
if (res.error) { | ||
} | ||
|
||
// @ts-expect-error redirect only, no paymentIntent expected | ||
if (res.paymentIntent) { | ||
} | ||
}); | ||
|
||
stripe | ||
.confirmPayment({ | ||
elements, | ||
confirmParams: {return_url: ''}, | ||
redirect: 'always', | ||
}) | ||
.then((res) => { | ||
if (res.error) { | ||
} | ||
|
||
// @ts-expect-error redirect only, no paymentIntent expected | ||
if (res.paymentIntent) { | ||
} | ||
}); | ||
|
||
stripe.confirmSetup({elements, confirmParams: {return_url: ''}}).then((res) => { | ||
if (res.error) { | ||
} | ||
|
||
// @ts-expect-error redirect only, no paymentIntent expected | ||
if (res.paymentIntent) { | ||
} | ||
}); | ||
|
||
stripe | ||
.confirmSetup({elements, confirmParams: {return_url: ''}, redirect: 'always'}) | ||
.then((res) => { | ||
if (res.error) { | ||
} | ||
|
||
// @ts-expect-error redirect only, no paymentIntent expected | ||
if (res.paymentIntent) { | ||
} | ||
}); | ||
|
||
stripe.createToken(cardElement, { | ||
currency: '', | ||
name: '', | ||
// @ts-expect-error: `extra_property` is not valid | ||
extra_property: '', | ||
}); | ||
|
||
// @ts-expect-error: `extra_property` is not valid | ||
stripe.createToken(ibanElement, { | ||
currency: '', | ||
account_holder_name: '', | ||
extra_property: '', | ||
}); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.