Skip to content

Commit

Permalink
fix forgot to export PossiblyReadAsNullable
Browse files Browse the repository at this point in the history
  • Loading branch information
tylim88 committed Sep 20, 2022
1 parent 827f770 commit 22b8869
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# HISTORY

## 1.4.3 20th Sept 22

- fix forgot to export `PossiblyReadAsNullable`

## 1.4.1 16th Sept 22

- fix set does not error when the node type is Record<string, T> and the input type is Record<number, T>
Expand Down
4 changes: 2 additions & 2 deletions codeForDoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

This folder consist of code for documentation.

It also serve as end to end test.
It also serves as end to end type test and some functionality test.

run `npm run link` to use this folder properly.
Run `npm run d-link` in root directory to use this folder properly.
52 changes: 52 additions & 0 deletions codeForDoc/src/guide/possibly_read_as_nullable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
MetaTypeCreator,
ServerTimestamp,
NumericKeyRecord,
PossiblyReadAsNullable,
createRef,
getDatabase,
get,
} from 'firesagejs'

export type Example = MetaTypeCreator<{
a: number | PossiblyReadAsNullable
b: number
}>
const exampleRef = createRef<Example>(getDatabase())

get(exampleRef()).then(dataSnapshot => {
// type of data is { a: number | null | undefined; b: number} | null
// PossiblyReadAsNullable union node read type with null and undefined
//
//
//
//
//
//
//
//
const data = dataSnapshot.val()
})

// you can union `PossiblyReadAsNullable` to any node
export type Example2 = MetaTypeCreator<
| {
b:
| {
c: boolean | PossiblyReadAsNullable
d:
| {
e: ServerTimestamp | PossiblyReadAsNullable
}
| PossiblyReadAsNullable
}
| PossiblyReadAsNullable
f:
| Record<string, 'a' | 'b' | 'c' | PossiblyReadAsNullable>
| PossiblyReadAsNullable
i:
| NumericKeyRecord<boolean | PossiblyReadAsNullable>
| PossiblyReadAsNullable
}
| PossiblyReadAsNullable
>
61 changes: 61 additions & 0 deletions codeForDoc/src/guide/removable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
MetaTypeCreator,
ServerTimestamp,
NumericKeyRecord,
Removable,
createRef,
getDatabase,
remove,
get,
} from 'firesagejs'

export type Example = MetaTypeCreator<{
a: number | Removable
b: number
}>
const exampleRef = createRef<Example>(getDatabase())

remove(exampleRef('a')) // ok
//
//
//
//
//
//
remove(
// @ts-expect-error
exampleRef('b')
) // not ok, because b is not removable

get(exampleRef()).then(dataSnapshot => {
// type of data is { a: number | null | undefined; b: number} | null
// Removable union node read type with null and undefined
//
//
//
//
//
//
//
//
const data = dataSnapshot.val()
})

// you can union `Removable` to any node
export type Example2 = MetaTypeCreator<
| {
b:
| {
c: boolean | Removable
d:
| {
e: ServerTimestamp | Removable
}
| Removable
}
| Removable
f: Record<string, 'a' | 'b' | 'c' | Removable> | Removable
i: NumericKeyRecord<boolean | Removable> | Removable
}
| Removable
>
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ const ref1 = ref('a/b/' + `${numericKey}`) // type error, type is string!
//
//
//
//
//
//
//
//
//
//
// @ts-expect-error
const ref2 = ref('a/c/' + `${nonNumericKey}`) // type error, type is string!

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firesagejs",
"version": "1.4.2",
"version": "1.4.3",
"description": "🔥Extreme Type Safe For Realtime Database Web, Write RTDB Code That Stand The Test Of Time",
"source": "src/index.ts",
"main": "dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export type {
ErrorHasNoChild,
FindNestedWriteTypeFromFullPath,
RemoveLastSlash,
PossiblyReadAsNullable,
} from './types'
2 changes: 1 addition & 1 deletion src/listeners/onDisconnect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('test onDisconnect', () => {

onDc.remove(
// @ts-expect-error
"Error: The 'b' node is not removable, only Removable type can be removed. Please check the MetaType and union 'b' node with Removable"
"Error: The 'b' node is not removable, only Removable node can be removed. Please check the MetaType and union 'b' node with Removable"
)

const onDc2 = onDisconnect(usersRef('b/h/abc/p'))
Expand Down
2 changes: 1 addition & 1 deletion src/types/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { TransformUndefinedToRoot } from './utils'
export type ErrorNotPushAble<T extends string | undefined> =
`Error: The ${TransformUndefinedToRoot<T>} node is not push-able, only PushAble<T> or PushAbleOnly<T> type can be pushed. Please check the MetaType and assign Push<T> or PushAbleOnly<T> type to ${TransformUndefinedToRoot<T>} node`
export type ErrorNotRemoveAble<T extends string | undefined> =
`Error: The ${TransformUndefinedToRoot<T>} node is not removable, only Removable type can be removed. Please check the MetaType and union ${TransformUndefinedToRoot<T>} node with Removable`
`Error: The ${TransformUndefinedToRoot<T>} node is not removable, only Removable node can be removed. Please check the MetaType and union ${TransformUndefinedToRoot<T>} node with Removable`

0 comments on commit 22b8869

Please sign in to comment.