Skip to content

Commit 9636d7d

Browse files
committed
Make value type unknown
1 parent 5753724 commit 9636d7d

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ This package "just works" with [`pg`](https://www.npmjs.com/package/pg) and [`my
7979
mssql.query(query.strings, ...query.values);
8080
```
8181

82+
### Stricter TypeScript
83+
84+
The default value is `unknown` to support [every possible input](https://github.com/blakeembrey/sql-template-tag/pull/26). If you want stricter TypeScript values you can create a new `sql` template tag function.
85+
86+
```ts
87+
import { Sql } from "sql-template-tag";
88+
89+
type SupportedValue =
90+
| string
91+
| number
92+
| SupportedValue[]
93+
| { [key: string]: SupportedValue };
94+
95+
function sql(
96+
strings: ReadonlyArray<string>,
97+
...values: Array<SupportedValue | Sql>
98+
) {
99+
return new Sql(strings, values);
100+
}
101+
```
102+
82103
## Related
83104

84105
Some other modules exist that do something similar:

src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
export type Value =
2-
| string
3-
| number
4-
| boolean
5-
| Date
6-
| null
7-
| undefined
8-
| Value[]
9-
| { [key: PropertyKey]: Value };
1+
/**
2+
* Values supported by SQL engine.
3+
*/
4+
export type Value = unknown;
5+
6+
/**
7+
* Supported value or SQL instance.
8+
*/
109
export type RawValue = Value | Sql;
1110

1211
/**

0 commit comments

Comments
 (0)