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

null from optional types conflicts with null as addr_none in TS wrappers #1198

Open
Gusarich opened this issue Dec 17, 2024 · 1 comment · May be fixed by #1223
Open

null from optional types conflicts with null as addr_none in TS wrappers #1198

Gusarich opened this issue Dec 17, 2024 · 1 comment · May be fixed by #1223
Labels
discussion Ideas that are not fully formed and require discussion scope: ts-wrappers TypeScript wrappers for Sandbox tests

Comments

@Gusarich
Copy link
Member

Currently, optional types are described as nullable ones (e.g. boolean | null), which is fine for all types except Address.
@ton/core handles addresses in such way that null means addr_none, and it was implemented in Tact in a similar way due to the original developer being the same person who made the library.
We want to rework addresses (#1119) for consistency and predictability, but nulls prevent us from doing so without refactoring either the ton-core library itself or generated TS wrappers for Tact contracts. Current maintainer of the library suggested the second option.

More precisely, we can make some type wrapper for Maybe that will be used instead of the | null thing to support null as a value itself. This will potentially resolve the problem and allow us to describe Maybe MsgAddress type which will look like Maybe<Address | ExternalAddress | null>.

What do you think? @anton-trunov @verytactical

@Gusarich Gusarich added discussion Ideas that are not fully formed and require discussion scope: ts-wrappers TypeScript wrappers for Sandbox tests labels Dec 17, 2024
@reverofevil
Copy link

reverofevil commented Dec 20, 2024

As far as I understand, we have Maybe<T> = T | null, while we should have done Maybe<T> = [T] | null.

export type Maybe<T> = Just<T> | Nothing
export type Just<T> = [T]
export const Just = <T>(t: T): Just<T> => [t];
export const getJust = <T>(t: Just<T>): T => t[0];
export const isJust = <T>(t: Maybe<T>): t is Just<T> => Boolean(t);
export type Nothing = null
export const Nothing: Nothing = null;
export const isNothing = <T>(t: Maybe<T>): t is Nothing => !t;

EDIT. Ha-ha, I wish it was that easy.

@verytactical verytactical linked a pull request Dec 20, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Ideas that are not fully formed and require discussion scope: ts-wrappers TypeScript wrappers for Sandbox tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants