網站搜尋

typescript - React native - 無法定義或推測 'userId' 的欄位類型


我剛剛升級了 React Native,在升級之前我的專案運行正常,但現在我遇到錯誤,請幫我解決。

這是錯誤

Column type for UserModel#userId is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
ExceptionsManager.js:76
Module AppRegistry is not a registered callable module (calling runApplication) 

我收到了關於許多欄位的錯誤。我不太理解這裡發生了什麼。每次我填好一個空缺 - 另一個欄位就無法被推測出來。當然,每次都明確定義將會是巨大的時間和精力浪費,因為 typeorm 的好處之一就是它能自動從資料庫類型獲取 TypeScript 類型。

這是我的使用者模型

import Realm, { ObjectSchema } from "realm";
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm/browser";

@Entity()
export class UserModel {

    @PrimaryGeneratedColumn()
    public id: number;
    @Column({nullable:true})
    public userId : string;
    @Column({nullable:true})
    public userName: string;
    @Column({nullable:true})
    public token: string;
    @Column({nullable:true})
    public refreshToken: string;
    @Column({nullable:true})
    public password: string
    @Column({nullable:true})
    public email: string;
    @Column({nullable:true})
    public mobile : string;
    @Column({nullable:true})
    public dob: string;
    @Column({nullable:true})
    public language: string;
    @Column({nullable:true})
    public gender: string;
    @Column({nullable:true})
    public qualification: string;
    @Column({nullable:true})
    public profession: string;
    @Column({nullable:true})
    public state: string;
    @Column({nullable:true})
    public district: string;
    @Column({nullable:true})
    public area: string;
    @Column({nullable:true})
    public parentArea: string;
    @Column({nullable:true})
    public subArea: string;

}

Package.json

{
  "name": "janmanch",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@babel/runtime": "^7.1.2",
    "@ldn0x7dc/react-native-view-pager": "0.0.9",
    "npm": "^6.1.0",
    "react": "16.3.1",
    "react-native": "0.57.0",
    "react-native-bottomsheet": "^1.9.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-device-info": "^0.21.5",
    "react-native-elements": "^0.19.1",
    "react-native-flexi-radio-button": "^0.2.2",
    "react-native-localization": "^1.0.10",
    "react-native-permissions": "^1.1.1",
    "react-native-splash-screen": "^3.0.9",
    "react-native-sqlite-storage": "^3.3.6",
    "react-native-swiper": "^1.5.13",
    "react-native-vector-icons": "^4.6.0",
    "react-navigation": "^2.3.1",
    "realm": "^2.8.4",
    "reflect-metadata": "^0.1.12",
    "remove": "^0.1.5",
    "typeorm": "^0.2.7"
  },
  "devDependencies": {
    "@babel/plugin-external-helpers": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.1.2",
    "@types/jest": "23.1.0",
    "@types/react": "16.3.18",
    "@types/react-native": "0.55.20",
    "@types/react-native-datepicker": "^1.6.3",
    "@types/react-navigation": "^2.0.5",
    "@types/react-test-renderer": "16.0.1",
    "babel-jest": "23.0.1",
    "babel-preset-react-native": "4.0.0",
    "jest": "23.1.0",
    "metro-react-native-babel-preset": "^0.47.0",
    "react-native-typescript-transformer": "1.2.10",
    "react-test-renderer": "16.3.1",
    "schedule": "0.4.0",
    "ts-jest": "22.4.6",
    "typescript": "2.9.2"
  },
  "jest": {
    "preset": "react-native",
    "transform": {
      "^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
      "\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ],
    "modulePaths": [
      "<rootDir>"
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "esModuleInterop": true,
    "jsx": "react",
    "module": "es6",
    "moduleResolution": "node",
    "noEmit": true,
    "noImplicitAny": true,
    "target": "es6",
/*Below code custom added*/
    "baseUrl": "./src",
    // "skipLibCheck": true,
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    // "outDir": "./build"
  },
  "include": ["./src"],
  "exclude": ["node_modules"]
}