Repository navigation
fix(typings): allow indexing Types with FieldPacket.type - #4582
Open
DylanMerigaud wants to merge 1 commit into
Open
DylanMerigaud wants to merge 1 commit into
DylanMerigaud wants to merge 1 commit into
Conversation
FieldPacket.type and columnType are numbers, so mysql.Types[field.type] failed with TS7053 under noImplicitAny. Fixes sidorares#3279 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment was marked as off-topic.
This comment was marked as off-topic.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3279
FieldPacket.typeandcolumnTypeare typed asnumber, butTypesonly declares its literal keys, so looking up a column's type name does not compile undernoImplicitAny:It is not ESM only: with
module: NodeNext, a CommonJS package and an ESM package get the same error.This adds
[key: number]: stringtoTypes, which is what TypeScript gives the reverse mapping of a numeric enum. The declared keys keep their types (Types.BLOBis stillnumber,Types[0x00]stillstring), and withnoUncheckedIndexedAccessan arbitrary code reads asstring | undefined. Two things get looser. A code that is not in the map, such asTypes[0x11], now compiles asstringinstead of failing, although it isundefinedat runtime. Andkeyof Typesnow includesnumberinstead of the 29 listed codes, so a union of codes derived from it becomesnumber, and an exhaustiveswitchover that union no longer compiles. I keptstringrather thanstring | undefinedbecauseTypeCastField.typealready assumes the same: the parsers read it from this map, and it is typed withoutundefined.The new lines in
test/tsc-build/{mysql,promise}/constants/Types.test.tsfail on master with TS7053 and pass here, and the@ts-expect-errorline fails if the lookup ever widens toany.npm run lint,npm run typecheck,npm run test:buildandnpm test(MySQL 8.3) pass locally, and the declaration also compiles on TypeScript 4.7, 4.9, 5.0, 5.4 and 5.9.This change was prepared with AI assistance (Claude).