Tsd problems encountered when using typescript2 and electron.

  node.js, question

I want to write a desktop application with the latest typescript2.0 and electron.
Using the new feature of typescript2, the @types/* of npm is used to manage tsd files.
However, there is always the problem of Duplicate identifier when performing tsc compilation.
May I know how to solve this problem?

The file structure is as follows

*
 |-main.ts
 |-package.json
 |-tsconfig.json
 \-app
 |-index.html

package.json

bracket
 "name": "fuck",
 "version": "0.1.0",
 "main": "./main.js",
 "scripts": {
 "prestart": "tsc",
 "start": "electron ."
 },
 "dependencies": {
 "@types/electron": "^1.3.22",
 "@types/node": "^6.0.40",
 "electron": "^1.4.0"
 },
 "devDependencies": {
 "typescript": "^2.0.0"
 bracket
 bracket

tsconfig.json

bracket
 "compilerOptions": {
 "target": "es5",
 "module": "commonjs",
 "moduleResolution": "node",
 "typeRoots": [
 "./node_modules/@types/"
 ],
 "types": [
 "node",
 "electron"
 bracket
 },
 "exclude": [
 "node_modules"
 bracket
 bracket

main.ts

import {app, BrowserWindow} from 'electron';
 
 class MyWindow extends BrowserWindow {
 constructor() {
 super({
 width: 800,
 height: 600
 });
 this.loadURL(`file://${__dirname}/app/index.html`);
 bracket
 bracket
 
 app.on("ready", () => {
 new MyWindow()
 });

Tsc execution results are as follows

node_modules/.1.3.22@@types/electron/index.d.ts(10,8): error TS2300: Duplicate identifier 'EventEmitter'.                                                                         
node_modules/.1.3.22@@types/electron/index.d.ts(28,7): error TS2300: Duplicate identifier 'Point'.                                                                                
node_modules/.1.3.22@@types/electron/index.d.ts(33,7): error TS2300: Duplicate identifier 'Size'.                                                                                 
node_modules/.1.3.22@@types/electron/index.d.ts(38,7): error TS2300: Duplicate identifier 'Rectangle'.                                                                            
node_modules/.1.3.22@@types/electron/index.d.ts(435,7): error TS2300: Duplicate identifier 'AppPathName'.                                                                         
node_modules/.1.3.22@@types/electron/index.d.ts(590,7): error TS2300: Duplicate identifier 'SetJumpListResult'.                                                                   
node_modules/.1.3.22@@types/electron/index.d.ts(743,8): error TS2300: Duplicate identifier 'BrowserWindow'.                                                                       
node_modules/.1.3.22@@types/electron/index.d.ts(1355,7): error TS2300: Duplicate identifier 'SwipeDirection'.                                                                     
node_modules/.1.3.22@@types/electron/index.d.ts(1357,7): error TS2300: Duplicate identifier 'ThumbarButtonFlags'.                                                                 
node_modules/.1.3.22@@types/electron/index.d.ts(1743,7): error TS2300: Duplicate identifier 'BrowserWindowType'.                                                                  
node_modules/.1.3.22@@types/electron/index.d.ts(1744,7): error TS2300: Duplicate identifier 'BrowserWindowTypeLinux'.                                                             
node_modules/.1.3.22@@types/electron/index.d.ts(1745,7): error TS2300: Duplicate identifier 'BrowserWindowTypeMac'.                                                               
node_modules/.1.3.22@@types/electron/index.d.ts(1746,7): error TS2300: Duplicate identifier 'BrowserWindowTypeWindows'.                                                           
node_modules/.1.3.22@@types/electron/index.d.ts(1828,7): error TS2300: Duplicate identifier 'ClipboardType'.                                                                      
node_modules/.1.3.22@@types/electron/index.d.ts(2321,7): error TS2300: Duplicate identifier 'IpcMainEventListener'.                                                               
node_modules/.1.3.22@@types/electron/index.d.ts(2369,7): error TS2300: Duplicate identifier 'IpcRendererEventListener'.                                                           
node_modules/.1.3.22@@types/electron/index.d.ts(2384,8): error TS2300: Duplicate identifier 'MenuItem'.                                                                           
node_modules/.1.3.22@@types/electron/index.d.ts(2419,7): error TS2300: Duplicate identifier 'MenuItemType'.                                                                       
node_modules/.1.3.22@@types/electron/index.d.ts(2420,7): error TS2300: Duplicate identifier 'MenuItemRole'.                                                                       
node_modules/.1.3.22@@types/electron/index.d.ts(2421,7): error TS2300: Duplicate identifier 'MenuItemRoleMac'.                                                                    
node_modules/.1.3.22@@types/electron/index.d.ts(2530,8): error TS2300: Duplicate identifier 'Menu'.                                                                               
node_modules/.1.3.22@@types/electron/index.d.ts(2585,8): error TS2300: Duplicate identifier 'NativeImage'.                                                                        
node_modules/.1.3.22@@types/electron/index.d.ts(2762,7): error TS2300: Duplicate identifier 'FileProtocolHandler'.                                                                
node_modules/.1.3.22@@types/electron/index.d.ts(2763,7): error TS2300: Duplicate identifier 'BufferProtocolHandler'.                                                              
node_modules/.1.3.22@@types/electron/index.d.ts(2764,7): error TS2300: Duplicate identifier 'StringProtocolHandler'.                                                              
node_modules/.1.3.22@@types/electron/index.d.ts(2765,7): error TS2300: Duplicate identifier 'HttpProtocolHandler'.                                                                
node_modules/.1.3.22@@types/electron/index.d.ts(2878,7): error TS2300: Duplicate identifier 'DisplayMetrics'.                                                                     
node_modules/.1.3.22@@types/electron/index.d.ts(2927,8): error TS2300: Duplicate identifier 'Session'.                                                                            
node_modules/.1.3.22@@types/electron/index.d.ts(3029,7): error TS2300: Duplicate identifier 'Permission'.                                                                         
node_modules/.1.3.22@@types/electron/index.d.ts(3326,8): error TS2300: Duplicate identifier 'BeforeRequestCallback'.                                                              
node_modules/.1.3.22@@types/electron/index.d.ts(3338,8): error TS2300: Duplicate identifier 'BeforeSendHeadersCallback'.                                                          
node_modules/.1.3.22@@types/electron/index.d.ts(3356,8): error TS2300: Duplicate identifier 'HeadersReceivedCallback'.                                                            
node_modules/.1.3.22@@types/electron/index.d.ts(4441,7): error TS2300: Duplicate identifier 'NewWindowDisposition'.                                                               
node_modules/.1.3.22@@types/electron/index.d.ts(4449,7): error TS2300: Duplicate identifier 'StopFindInPageAtion'.                                                                
node_modules/.1.3.22@@types/electron/index.d.ts(4451,7): error TS2300: Duplicate identifier 'CursorType'.                                                                         
node_modules/.1.3.22@@types/electron/index.d.ts(5265,8): error TS2300: Duplicate identifier 'Event'.                                                                              
node_modules/.1.3.22@@types/electron/index.d.ts(5435,7): error TS2300: Duplicate identifier 'GlobalEvent'.                                                                        
node_modules/.1.3.22@@types/electron/index.d.ts(5575,2): error TS2300: Duplicate identifier 'export='.  
node_modules/@types/electron/index.d.ts(10,8): error TS2300: Duplicate identifier 'EventEmitter'.                                                                                 
node_modules/@types/electron/index.d.ts(28,7): error TS2300: Duplicate identifier 'Point'.                                                                                        
node_modules/@types/electron/index.d.ts(33,7): error TS2300: Duplicate identifier 'Size'.                                                                                         
node_modules/@types/electron/index.d.ts(38,7): error TS2300: Duplicate identifier 'Rectangle'.                                                                                    
node_modules/@types/electron/index.d.ts(435,7): error TS2300: Duplicate identifier 'AppPathName'.                                                                                 
node_modules/@types/electron/index.d.ts(590,7): error TS2300: Duplicate identifier 'SetJumpListResult'.                                                                           
node_modules/@types/electron/index.d.ts(743,8): error TS2300: Duplicate identifier 'BrowserWindow'.                                                                               
node_modules/@types/electron/index.d.ts(1355,7): error TS2300: Duplicate identifier 'SwipeDirection'.                                                                             
node_modules/@types/electron/index.d.ts(1357,7): error TS2300: Duplicate identifier 'ThumbarButtonFlags'.                                                                         
node_modules/@types/electron/index.d.ts(1367,3): error TS2374: Duplicate string index signature.                                                                                  
node_modules/@types/electron/index.d.ts(1743,7): error TS2300: Duplicate identifier 'BrowserWindowType'.                                                                          
node_modules/@types/electron/index.d.ts(1744,7): error TS2300: Duplicate identifier 'BrowserWindowTypeLinux'.                                                                     
node_modules/@types/electron/index.d.ts(1745,7): error TS2300: Duplicate identifier 'BrowserWindowTypeMac'.                                                                       
node_modules/@types/electron/index.d.ts(1746,7): error TS2300: Duplicate identifier 'BrowserWindowTypeWindows'.                                                                   
node_modules/@types/electron/index.d.ts(1828,7): error TS2300: Duplicate identifier 'ClipboardType'.                                                                              
node_modules/@types/electron/index.d.ts(2321,7): error TS2300: Duplicate identifier 'IpcMainEventListener'.                                                                       
node_modules/@types/electron/index.d.ts(2369,7): error TS2300: Duplicate identifier 'IpcRendererEventListener'.                                                                   
node_modules/@types/electron/index.d.ts(2384,8): error TS2300: Duplicate identifier 'MenuItem'.                                                                                   
node_modules/@types/electron/index.d.ts(2419,7): error TS2300: Duplicate identifier 'MenuItemType'.                                                                               
node_modules/@types/electron/index.d.ts(2420,7): error TS2300: Duplicate identifier 'MenuItemRole'.                                                                               
node_modules/@types/electron/index.d.ts(2421,7): error TS2300: Duplicate identifier 'MenuItemRoleMac'.                                                                            
node_modules/@types/electron/index.d.ts(2530,8): error TS2300: Duplicate identifier 'Menu'.                                                                                       
node_modules/@types/electron/index.d.ts(2585,8): error TS2300: Duplicate identifier 'NativeImage'.                                                                                
node_modules/@types/electron/index.d.ts(2762,7): error TS2300: Duplicate identifier 'FileProtocolHandler'.                                                                        
node_modules/@types/electron/index.d.ts(2763,7): error TS2300: Duplicate identifier 'BufferProtocolHandler'.                                                                      
node_modules/@types/electron/index.d.ts(2764,7): error TS2300: Duplicate identifier 'StringProtocolHandler'.                                                                      
node_modules/@types/electron/index.d.ts(2765,7): error TS2300: Duplicate identifier 'HttpProtocolHandler'.                                                                        
node_modules/@types/electron/index.d.ts(2878,7): error TS2300: Duplicate identifier 'DisplayMetrics'.                                                                             
node_modules/@types/electron/index.d.ts(2927,8): error TS2300: Duplicate identifier 'Session'.                                                                                    
node_modules/@types/electron/index.d.ts(3029,7): error TS2300: Duplicate identifier 'Permission'.                                                                                 
node_modules/@types/electron/index.d.ts(3326,8): error TS2300: Duplicate identifier 'BeforeRequestCallback'.                                                                      
node_modules/@types/electron/index.d.ts(3338,8): error TS2300: Duplicate identifier 'BeforeSendHeadersCallback'.                                                                  
node_modules/@types/electron/index.d.ts(3356,8): error TS2300: Duplicate identifier 'HeadersReceivedCallback'.                                                                    
node_modules/@types/electron/index.d.ts(4438,3): error TS2374: Duplicate string index signature.                                                                                  
node_modules/@types/electron/index.d.ts(4441,7): error TS2300: Duplicate identifier 'NewWindowDisposition'.                                                                       
node_modules/@types/electron/index.d.ts(4449,7): error TS2300: Duplicate identifier 'StopFindInPageAtion'.                                                                        
node_modules/@types/electron/index.d.ts(4451,7): error TS2300: Duplicate identifier 'CursorType'.                                                                                 
node_modules/@types/electron/index.d.ts(5265,8): error TS2300: Duplicate identifier 'Event'.                                                                                      
node_modules/@types/electron/index.d.ts(5435,7): error TS2300: Duplicate identifier 'GlobalEvent'.                                                                                
node_modules/@types/electron/index.d.ts(5575,2): error TS2300: Duplicate identifier 'export='.

It looks like npm has a problem of duplicate definition between packages downloaded by version under node_modules and its Flexible connection.

Node and Electronics use the same way to manage tsd files, but this problem only occurs on Electronics.

I wanted to have a try, but I didn’t download electron for a long time. But it’s okay.@typesIt was downloaded.

I have seen how electron nodejs are@typesThe definition in does have many duplicate classes, but these classes are all defined in different namespaces, so theoretically it is not clear that duplicate definitions appear.

In addition, I tried tsc to compile your code (except my file name is index.ts) without any pressure. I don’t know if it’s the problem with electron, but the news looks like a compile problem.

clipboard.png