TypeScript introspection, add more custom types?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
I'm not sure if this is something that is lacking in the typescript definition. When I create a postgresql instance in typescript such as:
import postgres from 'postgres';
const sql = postgres({
host : awsSecret.host,
port : awsSecret.port,
database : awsSecret.dbname,
username : awsSecret.username,
password : awsSecret.password
});
If I console.log the sql object I get a lot of property of the sql such as
console.log
[Function: sql] {
types: [Function: typed],
typed: [Function: typed],
unsafe: [Function: unsafe],
array: [Function: array],
json: [Function: json],
file: [Function: file],
parameters: {},
largeObject: [Function: bound largeObject],
PostgresError: [class PostgresError extends Error],
options: {
host: [ 'xxxxxxxxxx' ],
port: [ xxxxxx ],
path: false,
database: 'xxxxx',
user: 'xxxxxxx',
pass: 'xxxxxxxxxx',
max: 10,
ssl: false,
idle_timeout: null,
connect_timeout: 30,
max_lifetime: [Function: max_lifetime],
max_pipeline: 100,
backoff: [Function: backoff],
keep_alive: 60,
prepare: true,
debug: false,
fetch_types: true,
publications: 'alltables',
target_session_attrs: undefined,
connection: { application_name: 'postgres.js' },
types: {},
onnotice: undefined,
onnotify: undefined,
onclose: undefined,
onparameter: undefined,
socket: undefined,
transform: {
undefined: undefined,
column: [Object],
value: [Object],
row: [Object]
},
parameters: {},
shared: { retries: 0, typeArrayMap: {} },
serializers: {
'0': [Function: serialize],
'16': [Function: serialize],
'17': [Function: serialize],
'21': [Function: serialize],
'23': [Function: serialize],
'25': [Function: serialize],
'26': [Function: serialize],
'114': [Function: serialize],
'700': [Function: serialize],
'701': [Function: serialize],
'1082': [Function: serialize],
'1114': [Function: serialize],
'1184': [Function: serialize],
'3802': [Function: serialize]
},
parsers: {
'16': [Function: parse],
'17': [Function: parse],
'21': [Function: parse],
'23': [Function: parse],
'26': [Function: parse],
'114': [Function: parse],
'700': [Function: parse],
'701': [Function: parse],
'1082': [Function: parse],
'1114': [Function: parse],
'1184': [Function: parse],
'3802': [Function: parse]
}
},
listen: [AsyncFunction: listen],
notify: [AsyncFunction: notify],
begin: [AsyncFunction: begin],
close: [AsyncFunction: close],
end: [AsyncFunction: end]
}
But not all these properties are available in typescript. Using keys of the sql instance only get the following properties:
'length',
'name',
'arguments',
'caller',
'constructor',
'apply',
'bind',
'call',
'toString',
Symbol(Symbol.hasInstance),
'__defineGetter__',
'__defineSetter__',
'hasOwnProperty',
'__lookupGetter__',
'__lookupSetter__',
'isPrototypeOf',
'propertyIsEnumerable',
'valueOf',
'__proto__',
'toLocaleString'
And VS Code also complains when I try to access sql.options. Is this because not all properties are exported in the type definition?
Is there a way in typescript to verify the integrity of the sql instance? Or is there a recommended way to do unit test in typescript for this lib?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named. Start by locating the TypeScript definition for the sql instance and compare its declared surface with the runtime properties shown in the issue, especially sql.options; then inspect the project's existing TypeScript testing entry points. Done means the intended public properties are typed and their behavior is covered by focused tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, postgresql, typescript
- Domain
- database, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100