Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ts-bindings): adhere to strict TS settings #1424

Closed
wants to merge 1 commit into from

Conversation

chadoh
Copy link
Contributor

@chadoh chadoh commented Jul 1, 2024

@fnando noticed that Astro does a strict TS check before building for production, which means that our current template fails to build packages built with bindings typescript-generated modules.

$ npm run build

> [email protected] build
> astro check && astro build

16:27:22 [check] Getting diagnostics for Astro files in /Users/fnando/Projects/stellar/soroban-hello-world...
src/contracts/hello_world.ts:4:34 - error ts(2379): Argument of type '{ rpcUrl: any; allowHttp: true; publicKey: undefined; networkPassphrase: "Test SDF Network ; September 2015"; contractId: "CC24T3LXL5ZGIWXZKPBP5YKCMLK3HO6CWUMZS5AV4NEBNCDKVUHQP4UA"; }' is not assignable to parameter of type 'ClientOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'publicKey' are incompatible.

  4 export default new Client.Client({
                                     ~
  5   ...Client.networks.testnet,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
  8   publicKey: undefined,
    ~~~~~~~~~~~~~~~~~~~~~~~
  9 });
    ~

tmp/src/index.ts:67:15 - error ts(4115): This parameter property must have an 'override' modifier because it overrides a member in base class 'Client'.

67   constructor(public readonly options: ContractClientOptions) {
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tmp/src/index.ts:10:1 - error ts(6192): All imports in import declaration are unused.

 10 import type {
    ~~~~~~~~~~~~~
 11   u32,
    ~~~~~~
...
 21   Duration,
    ~~~~~~~~~~~
 22 } from '@stellar/stellar-sdk/contract';
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tmp/src/index.ts:7:3 - error ts(6133): 'Result' is declared but its value is never read.

7   Result,
    ~~~~~~
tmp/src/index.ts:7:3 - error ts(1484): 'Result' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

7   Result,
    ~~~~~~
tmp/src/index.ts:6:3 - error ts(1484): 'ClientOptions' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

6   ClientOptions as ContractClientOptions,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tmp/src/index.ts:2:1 - error ts(6133): 'Address' is declared but its value is never read.

2 import { Address } from '@stellar/stellar-sdk';
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Result (8 files):
- 7 errors
- 0 warnings
- 0 hints

One of these needs to be fixed by removing this line from soroban-astro-templates initialize.js script.

The others are mostly fixed here. I still haven't figured out how to get astro check to chill it with the "X is declared but its value is never read" business, but when I run astro check locally these show up as hints, not errors.

@fnando noticed that Astro does a strict TS check before building for
production, which means that our current template fails to build
packages built with `bindings typescript`-generated modules.

```
$ npm run build

> [email protected] build
> astro check && astro build

16:27:22 [check] Getting diagnostics for Astro files in /Users/fnando/Projects/stellar/soroban-hello-world...
src/contracts/hello_world.ts:4:34 - error ts(2379): Argument of type '{ rpcUrl: any; allowHttp: true; publicKey: undefined; networkPassphrase: "Test SDF Network ; September 2015"; contractId: "CC24T3LXL5ZGIWXZKPBP5YKCMLK3HO6CWUMZS5AV4NEBNCDKVUHQP4UA"; }' is not assignable to parameter of type 'ClientOptions' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'publicKey' are incompatible.

  4 export default new Client.Client({
                                     ~
  5   ...Client.networks.testnet,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
  8   publicKey: undefined,
    ~~~~~~~~~~~~~~~~~~~~~~~
  9 });
    ~

tmp/src/index.ts:67:15 - error ts(4115): This parameter property must have an 'override' modifier because it overrides a member in base class 'Client'.

67   constructor(public readonly options: ContractClientOptions) {
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tmp/src/index.ts:10:1 - error ts(6192): All imports in import declaration are unused.

 10 import type {
    ~~~~~~~~~~~~~
 11   u32,
    ~~~~~~
...
 21   Duration,
    ~~~~~~~~~~~
 22 } from '@stellar/stellar-sdk/contract';
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tmp/src/index.ts:7:3 - error ts(6133): 'Result' is declared but its value is never read.

7   Result,
    ~~~~~~
tmp/src/index.ts:7:3 - error ts(1484): 'Result' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

7   Result,
    ~~~~~~
tmp/src/index.ts:6:3 - error ts(1484): 'ClientOptions' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.

6   ClientOptions as ContractClientOptions,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tmp/src/index.ts:2:1 - error ts(6133): 'Address' is declared but its value is never read.

2 import { Address } from '@stellar/stellar-sdk';
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Result (8 files):
- 7 errors
- 0 warnings
- 0 hints
```

One of these needs to be fixed by removing [this line](https://github.com/stellar/soroban-astro-template/blob/3c8e0bed309b466af5d25b69c8fe26f730905bb7/initialize.js#L99) from `soroban-astro-template`s `initialize.js` script.

The others are mostly fixed here. I still haven't figured out how to get
`astro check` to chill it with the "X is declared but its value is never
read" business, but when I run `astro check` locally these show up as
_hints_, not errors.
@chadoh chadoh requested a review from fnando July 2, 2024 17:53
Copy link
Member

@fnando fnando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not pretty, but does the trick! Thanks!

@chadoh
Copy link
Contributor Author

chadoh commented Jul 2, 2024

Sounds like we don’t need this

@chadoh chadoh closed this Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants