ant-design: error TS2304: Cannot find name 'T'

Version

2.10.4

Environment

Windows 10, Chrome 58.0, “react”: “^15.5.4”, “react-scripts-ts”: “2.2.0”, typescript: 2.3.2

Reproduction link

https://github.com/danprime/antdtypescript

Steps to reproduce

  1. Setup A ReactJS Project: create-react-app antdsample --scripts-version=react-scripts-ts
  2. Add ANTD yarn add antd --save
  3. Import a Button into App.tsx import {Button} from 'antd';
  4. Add <Button>Test Button</Button> within render() function.

ref: https://github.com/Microsoft/TypeScript-React-Starter

Or clone reproduction link, type npm install, then npm start.

What is expected?

Should render the basic Create React App page with a Button labeled “Test button”

What is actually happening?

I get a screen with the error:

Failed to compile /mnt/c/Users/danpr/workspace/ts2/node_modules/antd/lib/table/Column.d.ts (29,61): error TS2304: Cannot find name ‘T’. This error occurred during the build time and cannot be dismissed.


Here’s my tsconfig.json

{
  "compilerOptions": {
    "outDir": "build/dist",
    "module": "es6",
    "target": "es6",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "allowSyntheticDefaultImports": true
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ],
  "types": [
    "typePatches"
  ]
}

package.json

{
  "name": "ts2",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "^19.2.3",
    "@types/node": "^7.0.22",
    "@types/react": "^15.0.25",
    "@types/react-dom": "^15.5.0",
    "antd": "^2.10.4",
    "react": "^15.5.4",
    "react-dom": "^15.5.4"
  },
  "devDependencies": {
    "react-scripts-ts": "2.2.0"
  },
  "scripts": {
    "start": "react-scripts-ts start",
    "build": "react-scripts-ts build",
    "test": "react-scripts-ts test --env=jsdom",
    "eject": "react-scripts-ts eject"
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (11 by maintainers)

Most upvoted comments

Alternatively, while waiting the fix to be released, you can temporarily set "skipLibCheck": true in tsconfig.json.

I will try to find more info. But if we cannot solve this issue, I think we need to downgrade to TypeScript@2.2.x

Please, release.

Sorry, it is fixed. Need to change to "module": "es6", as well.

It seems that the issue has been closed by mistake.

This issue has been fixed, will be released soon.

It’s TypeScript’s issue, I try to downgrade TypeScript ot 2.2.x, the compiled result:

export default class Column<T> extends React.Component<ColumnProps<T>, React.ComponentState> {
}