Skip to content

Conversation

@netux
Copy link

@netux netux commented May 18, 2023

This is different from optional fields (field?: type) in that we can use null as a value instead of writing the property altogether.

For example:

interface MyType {
  optionalField?: boolean;
  nullableField: boolean | null;
  optionalAndNullableField?: boolean | null;
}

const obj: MyType = {
  // no optionalField here is fine, TypeScript won't complain

  nullableField: null, // this is fine as well, TypeScript won't complain

  optionalAndNullableField: null // this is fine as well, but we could also not include this field and TypeScript wouldn't complain either
}

Renamed old canBeNull to optional to be able to reuse canBeNull for the new functionality.

I didn't know what to do on action.func.ts, so I just defaulted canBeNull to false.

This is different from optional fields (`field?: type`) in that we can use `null` as a value instead of writing the property altogether.

For example:
```ts
interface MyType {
  optionalField?: boolean;
  nullableField: boolean | null;
  optionalAndNullableField?: boolean | null;
}

const obj: MyType = {
  // no optionalField here is fine, TypeScript won't complain

  nullableField: null, // this is fine as well, TypeScript won't complain

  optionalAndNullableField: null // this is fine as well, but we could also not include this field and TypeScript wouldn't complain either
}
```

Renamed old `canBeNull` to `optional` to be able to reuse `canBeNull` for the new functionality.

I didn't know what to do on action.func.ts, so I just defaulted `canBeNull` to false whenever TypeScript complained.
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

Successfully merging this pull request may close these issues.

2 participants