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

Wrong TS types #825

Open
cleverocheck opened this issue Dec 5, 2021 · 3 comments
Open

Wrong TS types #825

cleverocheck opened this issue Dec 5, 2021 · 3 comments

Comments

@cleverocheck
Copy link

Expected behavior and actual behavior

The project has a file, where is the wrong typing (group field) subject to the use of this model in this file (toTransactionStatus method). It says that the field must be of type enum, but in fact it is one of the enum values

Steps to reproduce the problem

import { RepositoryFactoryHttp } from 'symbol-sdk'

const repositoryFactory = new RepositoryFactoryHttp('http://wolf.importance.jp:3000')
const transactionStatusRepository = repositoryFactory.createTransactionStatusRepository()
transactionStatusRepository.getTransactionStatus('30F03BB1E2D422C19E1DEBFFB21C046EF8CD9FB32F5FF7C1A9235792162D20B1').subscribe(transactionStatus => {
    console.log(transactionStatus.group) // check console value and type in TS
})

Specifications like the version of the project, operating system, or hardware

  • sdk version: 1.0.2
@fboucquez
Copy link
Contributor

Hi @IgnatLomkov , I couldn't reproduce the issue. Could you show the logs?

@cleverocheck
Copy link
Author

Hi, @fboucquez, you probably do not fully understand me. If you do not consider the use of transactionStatus.group in other files, then there is correct typing. Code in this comment gives me "confirmed". But type TransactionGroupEnum cannot be applied in other parts of the sdk adequately. Let's say I want to perform such an action:

import { TransactionGroupEnum } from 'symbol-openapi-typescript-fetch-client'
import { RepositoryFactoryHttp } from 'symbol-sdk'

const repositoryFactory = new RepositoryFactoryHttp('http://wolf.importance.jp:3000')
const transactionRepository = repositoryFactory.createTransactionRepository()
const transactionStatusRepository = repositoryFactory.createTransactionStatusRepository()
transactionStatusRepository.getTransactionStatus('30F03BB1E2D422C19E1DEBFFB21C046EF8CD9FB32F5FF7C1A9235792162D20B1').subscribe(transactionStatus => {
    console.log(transactionStatus.group) // will output "confirmed"
    if(transactionStatus.group === TransactionGroupEnum.Failed) return
    transactionRepository.getTransaction('30F03BB1E2D422C19E1DEBFFB21C046EF8CD9FB32F5FF7C1A9235792162D20B1', transactionStatus.group) // TS error, but "Failed" excluded
        .subscribe(fullTransaction => console.log(fullTransaction))
})

There may of course be such a workaround, but it's still not what you want to use:

import { TransactionGroupEnum } from 'symbol-openapi-typescript-fetch-client'
import { RepositoryFactoryHttp, TransactionGroup } from 'symbol-sdk'

const repositoryFactory = new RepositoryFactoryHttp('http://wolf.importance.jp:3000')
const transactionRepository = repositoryFactory.createTransactionRepository()
const transactionStatusRepository = repositoryFactory.createTransactionStatusRepository()
transactionStatusRepository.getTransactionStatus('30F03BB1E2D422C19E1DEBFFB21C046EF8CD9FB32F5FF7C1A9235792162D20B1').subscribe(transactionStatus => {
    console.log(transactionStatus.group) // will output "confirmed"
    if (transactionStatus.group === TransactionGroupEnum.Failed) return
    transactionRepository.getTransaction('30F03BB1E2D422C19E1DEBFFB21C046EF8CD9FB32F5FF7C1A9235792162D20B1', transactionStatus.group as unknown as TransactionGroup)
        .subscribe(fullTransaction => console.log(fullTransaction))
})

The same typing inconsistency exists in other parts of the sdk

@fboucquez
Copy link
Contributor

Thanks @IgnatLomkov , you are right. We should split the TransactionGroupEnum with and without Failed. Failed value is not a valid value when searching or loading transactions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants