<ul dir="auto">
<li>[ x ] I tried using the latest <code class="notranslate">mongoose/mongoose.d.ts</code> <code class="notranslate">"@types/mongoose": "^4.6.1"</code> file in this repo and had problems.</li>
<li>[ x ] I tried using the latest stable version of tsc. <a href="https://www.npmjs.com/package/typescript" rel="nofollow">https://www.npmjs.com/package/typescript</a></li>
<li>[ x ] I want to talk about <code class="notranslate">mongoose/mongoose.d.ts</code>.
<ul dir="auto">
<li>The authors of that type definition are cc/ <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/simonxca/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/simonxca">@simonxca</a></li>
</ul>
</li>
</ul>
<p dir="auto">Hi, there is the problem with mongoose middleware definitions:<br>
According to the docs <a href="http://mongoosejs.com/docs/middleware.html" rel="nofollow">http://mongoosejs.com/docs/middleware.html</a> function signature for the hook post save is may looks like this (error: MongoError, doc: Document, next: (err?: NativeError) =&gt; void)</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="schema.post('save', function(error, doc, next) {
  if (error.name === 'MongoError' &amp;&amp; error.code === 11000) {
    next(new Error('There was a duplicate key error'));
  } else {
    next(error);
  }
});
"><pre class="notranslate"><span class="pl-s1">schema</span><span class="pl-kos">.</span><span class="pl-en">post</span><span class="pl-kos">(</span><span class="pl-s">'save'</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">,</span> <span class="pl-s1">doc</span><span class="pl-kos">,</span> <span class="pl-s1">next</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">===</span> <span class="pl-s">'MongoError'</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">error</span><span class="pl-kos">.</span><span class="pl-c1">code</span> <span class="pl-c1">===</span> <span class="pl-c1">11000</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s1">next</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">'There was a duplicate key error'</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
    <span class="pl-s1">next</span><span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">But typings has this</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    /**
     * Defines a post hook for the document
     * Post hooks fire on the event emitted from document instances of Models compiled
     *   from this schema.
     * @param method name of the method to hook
     * @param fn callback
     */
    post&lt;T extends Document&gt;(method: string, fn: (doc: T, next: (err?: NativeError) =&gt; void,
      ...otherArgs: any[]) =&gt; void): this;
    post&lt;T extends Document&gt;(method: string, fn: (doc: T) =&gt; void, ...args: any[]): this;"><pre class="notranslate">    <span class="pl-c">/**</span>
<span class="pl-c">     * Defines a post hook for the document</span>
<span class="pl-c">     * Post hooks fire on the event emitted from document instances of Models compiled</span>
<span class="pl-c">     *   from this schema.</span>
<span class="pl-c">     * <span class="pl-k">@param</span> method name of the method to hook</span>
<span class="pl-c">     * <span class="pl-k">@param</span> fn callback</span>
<span class="pl-c">     */</span>
    <span class="pl-s1">post</span><span class="pl-c1">&lt;</span><span class="pl-v">T</span> <span class="pl-s1">extends</span> <span class="pl-v">Document</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">method</span>: <span class="pl-s1">string</span><span class="pl-kos">,</span> <span class="pl-s1">fn</span>: <span class="pl-kos">(</span><span class="pl-s1">doc</span>: <span class="pl-v">T</span><span class="pl-kos">,</span> <span class="pl-s1">next</span>: <span class="pl-kos">(</span><span class="pl-s1">err</span>?<span class="pl-s1"></span>: <span class="pl-v">NativeError</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-k">void</span><span class="pl-kos">,</span>
      ...<span class="pl-s1">otherArgs</span>: <span class="pl-s1">any</span><span class="pl-kos">[</span><span class="pl-s1"></span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-k">void</span><span class="pl-kos">)</span>: <span class="pl-smi">this</span><span class="pl-kos">;</span>
    <span class="pl-s1">post</span><span class="pl-c1">&lt;</span><span class="pl-v">T</span> <span class="pl-s1">extends</span> <span class="pl-v">Document</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">method</span>: <span class="pl-s1">string</span><span class="pl-kos">,</span> <span class="pl-s1">fn</span>: <span class="pl-kos">(</span><span class="pl-s1">doc</span>: <span class="pl-v">T</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-k">void</span><span class="pl-kos">,</span> ...<span class="pl-s1">args</span>: <span class="pl-s1">any</span><span class="pl-kos">[</span><span class="pl-s1"></span><span class="pl-kos">]</span><span class="pl-kos">)</span>: <span class="pl-smi">this</span><span class="pl-kos"></span><span class="pl-kos">;</span></pre></div>
<p dir="auto">in other words, <code class="notranslate">error</code> signature was omitted</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I tried using the <code class="notranslate">@types/xxxx</code> package and had problems.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I tried using the latest stable version of tsc. <a href="https://www.npmjs.com/package/typescript" rel="nofollow">https://www.npmjs.com/package/typescript</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have a question that is inappropriate for <a href="https://stackoverflow.com/" rel="nofollow">StackOverflow</a>.  (Please ask any appropriate questions there).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> <a href="https://github.com/blog/821-mention-somebody-they-re-notified">Mention</a> the authors (see <code class="notranslate">Definitions by:</code> in <code class="notranslate">index.d.ts</code>) so they can respond.
<ul dir="auto">
<li>Authors: <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/alloy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/alloy">@alloy</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gyzerok/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gyzerok">@gyzerok</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/huhuanming/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/huhuanming">@huhuanming</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jeremistadler/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jeremistadler">@jeremistadler</a></li>
</ul>
</li>
</ul>
<hr>
<p dir="auto">Hey there! I'm combining Node, React, React DOM and React Native code in the same codebase (So that I can generate simultaneously iOS, Android and Web apps with Server-side rendering support), and I'm hitting the following errors in the type definitions for React native:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:60:13
    TS2451: Cannot redeclare block-scoped variable 'global'.

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:84:13
    TS2300: Duplicate identifier 'require'.

ERROR in [at-loader] ./node_modules/@types/react-native/index.d.ts:8872:11
    TS2451: Cannot redeclare block-scoped variable 'global'.

ERROR in [at-loader] ./node_modules/@types/react-native/index.d.ts:8873:14
    TS2300: Duplicate identifier 'require'.

ERROR in [at-loader] ./node_modules/@types/webpack-env/index.d.ts:186:13
    TS2300: Duplicate identifier 'require'."><pre class="notranslate"><code class="notranslate">ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:60:13
    TS2451: Cannot redeclare block-scoped variable 'global'.

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:84:13
    TS2300: Duplicate identifier 'require'.

ERROR in [at-loader] ./node_modules/@types/react-native/index.d.ts:8872:11
    TS2451: Cannot redeclare block-scoped variable 'global'.

ERROR in [at-loader] ./node_modules/@types/react-native/index.d.ts:8873:14
    TS2300: Duplicate identifier 'require'.

ERROR in [at-loader] ./node_modules/@types/webpack-env/index.d.ts:186:13
    TS2300: Duplicate identifier 'require'.
</code></pre></div>
<p dir="auto">It looks like React Native redefines <code class="notranslate">global</code> and <code class="notranslate">require</code>:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare global {
    const global: GlobalStatic;
    function require(name: string): any;

    /**
     * This variable is set to true when react-native is running in Dev mode
     * Typical usage:
     * &lt;code&gt; if (__DEV__) console.log('Running in dev mode')&lt;/code&gt;
     */
    var __DEV__: boolean
}"><pre class="notranslate"><span class="pl-k">declare</span> global <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">global</span>: <span class="pl-smi">GlobalStatic</span><span class="pl-kos">;</span>
    <span class="pl-k">function</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s1">name</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span><span class="pl-kos">;</span>

    <span class="pl-c">/**</span>
<span class="pl-c">     * This variable is set to true when react-native is running in Dev mode</span>
<span class="pl-c">     * Typical usage:</span>
<span class="pl-c">     * &lt;code&gt; if (__DEV__) console.log('Running in dev mode')&lt;/code&gt;</span>
<span class="pl-c">     */</span>
    <span class="pl-k">var</span> <span class="pl-c1">__DEV__</span>: <span class="pl-smi">boolean</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Since these are already defined by <code class="notranslate">@types/node</code>, the compiler complains. I was able to work around the issue by adding the following option to my <code class="notranslate">tsconfig.json</code> file, however I'd like to avoid doing that if possible:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
   &quot;skipLibCheck&quot;: true
}"><pre class="notranslate">{
   <span class="pl-ent">"skipLibCheck"</span>: <span class="pl-c1">true</span>
}</pre></div>
<p dir="auto">Thanks in advance</p>