账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    问一个typescript 类型收窄问题
    82
    0
    tsconfig.json{"compilerOptions": { "outDir": "build/dist", "module": "esnext", "target": "esnext", "lib": ["esnext", "dom"], "sourceMap": true, "baseUrl": ".", "jsx": "react-jsx", "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "moduleResolution": "node", "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "suppressImplicitAnyIndexErrors": true, "noUnusedLocals": true, "allowJs": true, "skipLibCheck": true, "experimentalDecorators": true, "strict": true, "paths": { "@/*": ["./src/*"], "@@/*": ["./src/.umi/*"], } }}eslintrc.jsmodule.exports = { extends: [require.resolve('@umijs/fabric/dist/eslint')], globals: { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true, page: true, REACT_APP_ENV: true, },};更新问题class A { readonly sdkType ='a' constructor () { }}class B { readonly sdkType ='b' constructor () { }}function test(this: A): 1;function test(this: B): 2;function test(this:A|B) { if (this instanceof A) { return 1 } else { return 2 }}// 这里在调用的时候又报错const d = test.call(new A)我的sdkType 就是做唯一类型判断的原问题function test<T extends string | number>(params: T): T extends number ? 1 : 2 { // 这里做了类型判断 if (typeof params === 'number') { // 这里报错了 return 1 } else { // 这里报错了 return 2 }}
    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    • 晨尘缘 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部