Skip to content

Commit

Permalink
fix(types): support encoding for string type cast (#2407)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup authored Jan 29, 2024
1 parent 6bd0120 commit 1dc2011
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions test/tsc-build/strict-checks/typeCast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import { access, sql } from '../promise/baseConnection.js';
const type: string = field.type;
const buffer: Buffer | null = field.buffer();
const string: string | null = field.string();
const stringWithEncoding: string | null = field.string('utf-8');
const geometry:
| { x: number; y: number }
| { x: number; y: number }[]
| null = field.geometry();

console.log(db, length, name, table, type);
console.log(buffer, string, geometry);
console.log(buffer, string, stringWithEncoding, geometry);

return next();
},
Expand Down Expand Up @@ -64,13 +65,14 @@ import { access, sql } from '../promise/baseConnection.js';
const type: string = field.type;
const buffer: Buffer | null = field.buffer();
const string: string | null = field.string();
const stringWithEncoding: string | null = field.string('utf-8');
const geometry:
| { x: number; y: number }
| { x: number; y: number }[]
| null = field.geometry();

console.log(db, length, name, table, type);
console.log(buffer, string, geometry);
console.log(buffer, string, stringWithEncoding, geometry);

return next();
},
Expand Down Expand Up @@ -101,13 +103,14 @@ import { access, sql } from '../promise/baseConnection.js';
const type: string = field.type;
const buffer: Buffer | null = field.buffer();
const string: string | null = field.string();
const stringWithEncoding: string | null = field.string('utf-8');
const geometry:
| { x: number; y: number }
| { x: number; y: number }[]
| null = field.geometry();

console.log(db, length, name, table, type);
console.log(buffer, string, geometry);
console.log(buffer, string, stringWithEncoding, geometry);

return next();
},
Expand Down Expand Up @@ -138,13 +141,14 @@ import { access, sql } from '../promise/baseConnection.js';
const type: string = field.type;
const buffer: Buffer | null = field.buffer();
const string: string | null = field.string();
const stringWithEncoding: string | null = field.string('utf-8');
const geometry:
| { x: number; y: number }
| { x: number; y: number }[]
| null = field.geometry();

console.log(db, length, name, table, type);
console.log(buffer, string, geometry);
console.log(buffer, string, stringWithEncoding, geometry);

return next();
},
Expand Down
2 changes: 1 addition & 1 deletion typings/mysql/lib/parsers/typeCast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Field = Type & {
db: string;
table: string;
name: string;
string: () => string | null;
string: (encoding?: BufferEncoding | string | undefined) => string | null;
buffer: () => Buffer | null;
geometry: () => Geometry | Geometry[] | null;
};
Expand Down

0 comments on commit 1dc2011

Please sign in to comment.