Skip to content

Commit 9a61040

Browse files
committed
chore(ts): fix errors related to this keyword
app.ts:22:24 - error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. app.ts:20:42 An outer value of 'this' is shadowed by this container. Correction for cd71fb1 commit. Part of #35
1 parent 1fb04f3 commit 9a61040

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

examples/ts/express/mysql/app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const pool = mysql.createPool({
1313
password: process.env.DB_PASSWORD,
1414
database: process.env.DB_NAME,
1515
// Support of named placeholders (https://github.com/mysqljs/mysql#custom-format)
16-
queryFormat: function(query, values) {
16+
queryFormat: function(this: mysql.Pool, query, values) {
1717
if (!values) {
1818
return query
1919
}
20-
return query.replace(/\:(\w+)/g, function(matchedSubstring: string, capturedValue: string) {
20+
return query.replace(/\:(\w+)/g, function(this: mysql.Pool, matchedSubstring: string, capturedValue: string) {
2121
if (values.hasOwnProperty(capturedValue)) {
2222
return this.escape(values[capturedValue])
2323
}

src/templates/app.ts.ejs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ const pool = mysql.createPool({
1313
password: process.env.DB_PASSWORD,
1414
database: process.env.DB_NAME,
1515
// Support of named placeholders (https://github.com/mysqljs/mysql#custom-format)
16-
queryFormat: function(query, values) {
16+
queryFormat: function(this: mysql.Pool, query, values) {
1717
if (!values) {
1818
return query
1919
}
2020
<%- // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_the_replacement -%>
21-
return query.replace(/\:(\w+)/g, function(matchedSubstring: string, capturedValue: string) {
21+
return query.replace(/\:(\w+)/g, function(this: mysql.Pool, matchedSubstring: string, capturedValue: string) {
2222
if (values.hasOwnProperty(capturedValue)) {
2323
return this.escape(values[capturedValue])
2424
}

0 commit comments

Comments
 (0)