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

feat(typescript): Add support explicit null values #5612

Merged
merged 31 commits into from
Jan 15, 2025

Conversation

amckinney
Copy link
Member

@amckinney amckinney commented Jan 14, 2025

Now that the Fern definition supports nullable properties (re: #5601), this upgrades the TypeScript generator to IRv55 to support this feature. For example, consider the following Fern definition:

types:
  User:
    properties:
      name: string
      tags: nullable<list<string>>
      metadata: optional<nullable<Metadata>>

  Metadata:
    properties:
      createdAt: datetime
      updatedAt: datetime
      avatar: nullable<string>
      activated: optional<nullable<boolean>>

The generated TypeScript types look like the following:

export interface User {
    name: string;
    tags: string[] | null;
    metadata?: Metadata | null;
}

export interface Metadata {
    createdAt: Date;
    updatedAt: Date;
    avatar: string | null;
    activated?: boolean | null;
}

Note that this also temporarily disables the dynamic snippet tests so that we can more confidently test the TypeScript SDK generator until example generation is fixed.

@amckinney amckinney requested a review from dsinghvi as a code owner January 14, 2025 18:34
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (usernames != null) {
if (Array.isArray(usernames)) {
_queryParams["usernames"] = usernames.map((item) => item);
Copy link
Member

Choose a reason for hiding this comment

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

unrelated, but are we creating a copy of an array here? I think there are simpler ways to do this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea it looks like it - I have a feeling this is because we always map over the array values and (optionally) perform a string mapper function (e.g. item.toString()), so it's simpler to always use the .map expression.

We can take a closer look here though.

Copy link

github-actions bot commented Jan 15, 2025

@amckinney amckinney merged commit 61f3405 into main Jan 15, 2025
17 of 18 checks passed
@amckinney amckinney deleted the amckinney/typescript-nullable branch January 15, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants