Skip to content

Generic inferred as string when a union member is T | (string & {}): false TS2322/TS2345 (breaks antd Table) #1058

Closed

Description

@YoungiiJC

Summary

oxlint --type-aware --type-check reports false TS2322/TS2345 errors on code that both tsc and tsgo --noEmit accept: when a call infers a generic T that also appears in a union with (string & {}) (the common "string with autocomplete" idiom), tsgolint resolves T as string instead of the type inferred from the other arguments.

The practical impact is large: antd's Table uses exactly this idiom (SpecialString<T> = T | (string & {}) in rc-table's DataIndex), so essentially every <Table dataSource={rows} columns={[{ dataIndex: ... }]} /> in an antd codebase reports Type 'Rec[]' is not assignable to type 'readonly string[]', and every record in a column render / rowKey callback resolves as string.

Versions

  • oxlint: 1.72.0
  • oxlint-tsgolint: 0.24.0
  • typescript: 5.9.3 (clean)
  • @typescript/native-preview (tsgo): 7.0.0-dev.20260527.2 (clean)
  • Platform: Linux x64

Minimal reproduction (zero runtime deps)

src/repro.ts:

interface Column<T> {
  dataIndex?: (T | (string & {}))[]
}

declare function table<T>(rows: readonly T[], columns: Column<T>[]): void

declare const rows: { id: number }[]

table(rows, [{ dataIndex: ['id'] }])

tsconfig.json:

{
  "compilerOptions": {
    "strict": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "noEmit": true
  },
  "include": ["src"]
}

package.json devDependencies: [email protected], @typescript/[email protected], [email protected], [email protected].

$ npx tsc --noEmit    # exit 0
$ npx tsgo --noEmit   # exit 0
$ npx oxlint --type-aware --type-check src/
src/repro.ts:9:7: error typescript(TS2345): Argument of type '{ id: number; }[]' is not assignable to parameter of type 'readonly string[]'.

Expected: no diagnostics (match tsc/tsgo — T infers as { id: number } from rows; 'id' matches the (string & {}) union member).
Actual: T is resolved as string, producing the TS2345 above.

Bisection notes, in case they help locate it:

  • Replacing (string & {}) with plain string in the union → no divergence (clean everywhere).
  • Moving the union out of the object property into a direct parameter (keys: (T | (string & {}))[]) → no divergence. The union seems to need to sit behind an object-literal property for the bad candidate to win.

Real-world shape (antd Table)

With [email protected], [email protected], @types/[email protected], jsx: react-jsx:

import { Table } from 'antd'

type Rec = { alert: { id: string; name: string } }
const rows: Rec[] = [{ alert: { id: '1', name: 'a' } }]

export function App() {
  return (
    <Table
      dataSource={rows}
      rowKey={(record) => record.alert.id}
      columns={[
        {
          title: 'Name',
          dataIndex: ['alert', 'name'],
          key: 'name',
          render: (_, record) => record.alert.name,
        },
      ]}
    />
  )
}

tsc / tsgo: clean. oxlint --type-aware --type-check:

src/App.tsx:9:7: error typescript(TS2322): Type 'Rec[]' is not assignable to type 'readonly string[]'.
src/App.tsx:10:34: error typescript(TS2339): Property 'alert' does not exist on type 'string'.
src/App.tsx:16:41: error typescript(TS2339): Property 'alert' does not exist on type 'string'.

The string comes in through rc-table's DataIndex<T>, whose union includes SpecialString<T> = T | (string & {}). Same result when the table is wrapped with styled-components (styled(Table)\...` as typeof Table), which is how we first hit it. Related to (but distinct from) the fixed #706/#864 — there the generic collapsed to any; here it resolves to string`, on 0.24.0.

Additional observation: tsconfig exclude not honored

While reducing this I noticed --type-check also type-checks files the tsconfig excludes. Adding to the repro:

src/excluded.e2e.ts:

import { thing } from 'not-a-real-module'
export const x: number = thing

and "exclude": ["**/*.e2e.ts"] in the tsconfig. tsc/tsgo skip the file; oxlint reports:

src/excluded.e2e.ts:1:23: error typescript(TS2307): Cannot find module 'not-a-real-module' or its corresponding type declarations.

Happy to split that into a separate issue if you prefer.

Activity

  1. self-assigned this
    on Jul 7, 2026
  2. camc314 commented on Jul 7, 2026

    @camc314
    Contributor

    Thanks for the detailed report. This is an upstream typescript-go inference regression rather than a TSGolint configuration issue. It reproduces with TSGolint’s pinned tsgo and current upstream.

    Please follow:

    We’ll pick up the upstream fix once typescript-go has fixed this issue.

    Thanks!

  3. added theissue type on Jul 7, 2026
  4. changed the title [-]Generic inferred as `string` when a union member is `T | (string & {})`: false TS2322/TS2345, diverges from tsc/tsgo (breaks antd Table)[/-] [+]Generic inferred as `string` when a union member is `T | (string & {})`: false TS2322/TS2345 (breaks antd Table)[/+] on Jul 7, 2026
  5. camc314 commented on Jul 16, 2026

    @camc314
    Contributor

    Additional observation: tsconfig exclude not honored

    While reducing this I noticed --type-check also type-checks files the tsconfig excludes. Adding to the repro:

    src/excluded.e2e.ts:

    import { thing } from 'not-a-real-module'
    export const x: number = thing
    and "exclude": ["**/*.e2e.ts"] in the tsconfig. tsc/tsgo skip the file; oxlint reports:

    src/excluded.e2e.ts:1:23: error typescript(TS2307): Cannot find module 'not-a-real-module' or its corresponding type declarations.
    

    Happy to split that into a separate issue if you prefer.

    This is expected behaviour, if you don't want the file to be linted, add it to your ignore patterns.

  6. camc314 commented on Aug 3, 2026

    @camc314
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions