Skip to content

Commit 1dc2011

Browse files
authored
fix(types): support encoding for string type cast (#2407)
1 parent 6bd0120 commit 1dc2011

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

test/tsc-build/strict-checks/typeCast.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ import { access, sql } from '../promise/baseConnection.js';
2727
const type: string = field.type;
2828
const buffer: Buffer | null = field.buffer();
2929
const string: string | null = field.string();
30+
const stringWithEncoding: string | null = field.string('utf-8');
3031
const geometry:
3132
| { x: number; y: number }
3233
| { x: number; y: number }[]
3334
| null = field.geometry();
3435

3536
console.log(db, length, name, table, type);
36-
console.log(buffer, string, geometry);
37+
console.log(buffer, string, stringWithEncoding, geometry);
3738

3839
return next();
3940
},
@@ -64,13 +65,14 @@ import { access, sql } from '../promise/baseConnection.js';
6465
const type: string = field.type;
6566
const buffer: Buffer | null = field.buffer();
6667
const string: string | null = field.string();
68+
const stringWithEncoding: string | null = field.string('utf-8');
6769
const geometry:
6870
| { x: number; y: number }
6971
| { x: number; y: number }[]
7072
| null = field.geometry();
7173

7274
console.log(db, length, name, table, type);
73-
console.log(buffer, string, geometry);
75+
console.log(buffer, string, stringWithEncoding, geometry);
7476

7577
return next();
7678
},
@@ -101,13 +103,14 @@ import { access, sql } from '../promise/baseConnection.js';
101103
const type: string = field.type;
102104
const buffer: Buffer | null = field.buffer();
103105
const string: string | null = field.string();
106+
const stringWithEncoding: string | null = field.string('utf-8');
104107
const geometry:
105108
| { x: number; y: number }
106109
| { x: number; y: number }[]
107110
| null = field.geometry();
108111

109112
console.log(db, length, name, table, type);
110-
console.log(buffer, string, geometry);
113+
console.log(buffer, string, stringWithEncoding, geometry);
111114

112115
return next();
113116
},
@@ -138,13 +141,14 @@ import { access, sql } from '../promise/baseConnection.js';
138141
const type: string = field.type;
139142
const buffer: Buffer | null = field.buffer();
140143
const string: string | null = field.string();
144+
const stringWithEncoding: string | null = field.string('utf-8');
141145
const geometry:
142146
| { x: number; y: number }
143147
| { x: number; y: number }[]
144148
| null = field.geometry();
145149

146150
console.log(db, length, name, table, type);
147-
console.log(buffer, string, geometry);
151+
console.log(buffer, string, stringWithEncoding, geometry);
148152

149153
return next();
150154
},

typings/mysql/lib/parsers/typeCast.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Field = Type & {
4343
db: string;
4444
table: string;
4545
name: string;
46-
string: () => string | null;
46+
string: (encoding?: BufferEncoding | string | undefined) => string | null;
4747
buffer: () => Buffer | null;
4848
geometry: () => Geometry | Geometry[] | null;
4949
};

0 commit comments

Comments
 (0)