alpaca-ts
alpaca-ts copied to clipboard
Does not compile with TypeScript 4.7 module = nodenext
Description
Can't compile TypeScript project using @master-chief/alpaca with module = nodenext
in tsconfig.json.
Expected TypeScript compilation pass.
Reproduction
- Install latest TypeScript (4.7.3)
- Install latest @master-chief/alpaca (6.3.20):
npm i @master-chief/alpaca
- Create tsconfig with module=NodeNext:
"compilerOptions": { "target": "es2020", "module": "NodeNext", "strict": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true },
- Create index.ts importing alpaca stuff:
import { AlpacaClient, AlpacaStream } from '@master-chief/alpaca';
- Try to compile TypeScript:
tsc
Logs
error TS7016: Could not find a declaration file for module '@master-chief/alpaca'. '.../node_modules/@master-chief/alpaca/dist/mjs/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/master-chief__alpaca` if it exists or add a new declaration (.d.ts) file containing `declare module '@master-chief/alpaca';`
Will investigate.
I have the same problem. A hotfix or a workaround, would be really appreciated! 😄
I have the same problem. A hotfix or a workaround, would be really appreciated! 😄
Error:
been busy 😢 ill try today
well a temporary workaround would be
// @ts-ignore
import { AlpacaClient } from "@master-chief/alpaca";
and im able to compile with
{
"compilerOptions": {
"target": "es2020",
"module": "NodeNext",
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}
You can also do..
{
"compilerOptions": {
...
"noImplicitAny": false,
}
}
I don't know why its unable to find the typings, something to do with the way typescript ^4.8.0-dev.20220619
handles resolution? If I may ask why are you using the nightly version of typescript anyways? It is designated as unstable.
Hmm trying one more thing.
Yeah idk. Works fine on every non-dev typescript version for me.
Yeah idk. Works fine on every non-dev typescript version for me.
Hmmm interesting. I was using TypeScript version 4.7.3 there and got the error. I tried installing the 4.6.3 version and still got the same error.
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
@WinstonNau ill try
@117 Maybe the reason is that dist/cjs/*.cjs
files are looking for typings in @types/*.d.cts
files (not in @types/*.d.ts
)? One idea is instead of renaming dist/cjs/*.js
-> dist/cjs/*.cjs
generate simple package.json
in dist/cjs
:
{"type":"commonjs"}
will try this!
@WinstonNau ill try
Thank you! Let me know if you might have a fix for this problem :)
oh my god .d.cts
works
i'm going to write a new build script and config which generates the new declarations tomorrow. too tired right now
delaying another day 😞 work is kicking my ass
Ok! Before I publish it please test and let me know if this solves it for you. Try npm i 117/alpaca
and let me know :)
"dependencies": {
"@master-chief/alpaca": "github:117/alpaca"
},
I have tested this personally with the following tsconfig.
{
"compilerOptions": {
"target": "es2020",
"module": "NodeNext",
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}
@WinstonNau @vitalets
@117 does not compile for me :(
npx tsc
node_modules/@master-chief/alpaca/dist/cjs/index.d.cts:10:353 - error TS2307: Cannot find module './entities' or its corresponding type declarations.
10 export { Account, Order, OrderCancelation, Position, Asset, Watchlist, Calendar, Clock, DefaultCredentials, OAuthCredentials, AccountConfigurations, NonTradeActivity, TradeActivity, Activity, PortfolioHistory, Bar, Bar_v1, Quote, LastQuote_v1, LastTrade_v1, Trade, PageOfBars, PageOfQuotes, PageOfTrades, Snapshot, DataSource, Channel, Message, } from './entities';
~~~~~~~~~~~~
node_modules/@master-chief/alpaca/dist/cjs/index.d.cts:11:449 - error TS2307: Cannot find module './params' or its corresponding type declarations.
11 export { GetOrder, GetOrders, PlaceOrder, ReplaceOrder, CancelOrder, GetPosition, ClosePosition, GetAsset, GetAssets, GetWatchList, CreateWatchList, UpdateWatchList, AddToWatchList, RemoveFromWatchList, DeleteWatchList, GetCalendar, UpdateAccountConfigurations, GetAccountActivities, GetPortfolioHistory, GetBars, GetBars_v1, GetTrades, GetQuotes, GetSnapshot, GetSnapshots, GetLastTrade_v1, GetLastQuote_v1, BarsV1Timeframe, BarsTimeframe, } from './params';
~~~~~~~~~~
node_modules/@master-chief/alpaca/dist/cjs/stream.d.cts:1:23 - error TS2688: Cannot find type definition file for 'ws'.
1 /// <reference types="ws" />
~~
node_modules/isomorphic-ws/index.d.ts:6:28 - error TS7016: Could not find a declaration file for module 'ws'. '/Users/vitalets/projects/tmp/node_modules/ws/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`
6 import WebSocket = require('ws')
~~~~
Found 4 errors in 3 files.
Errors Files
2 node_modules/@master-chief/alpaca/dist/cjs/index.d.cts:10
1 node_modules/@master-chief/alpaca/dist/cjs/stream.d.cts:1
1 node_modules/isomorphic-ws/index.d.ts:6
Environment: npm ls
[email protected] /projects/tmp
├── @master-chief/[email protected] (git+ssh://[email protected]/117/alpaca.git#79a216be9073b01587b2bc599919275bbaa28797)
└── [email protected]
cat tsconfig.json
{
"compilerOptions": {
"target": "es2020",
"module": "NodeNext",
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"noEmit": true,
},
"include": [ "src" ]
}
node -v
v16.14.0
I get this error in WebStorm
and this error after starting the app:
and this is my tsconfig (the module automatically changes to esnext so I can't use NodeNext)
Hi @117! Any update on this issue? =)
no update ):
v7 is on the way, you can track it here #113
I also received error TS7016 when trying to use @master-chief/alpaca v6.3.20 in a TS project using ESM with moduleResolution
set to node16
and module
set to es2022
. Upgrading to @master-chief/alpaca-ts v7.0.9-alpha solved the issue for me! 👍
@117 I also tried "@master-chief/alpaca": "github:117/alpaca"
. It works when I set "skipLibCheck" to true
in my TS config. Given that this library is currently the best solution for TS-ESM projects (as it is executable and provides typings), can you make a release from it?
Hey @117, today I noticed that the error
callback of stream.ts
is typed wrongly: https://github.com/alpacahq/alpaca-ts/blob/d4a2b7bae909f8c4e4d80752940c1a9cd60e7617/src/stream.ts#L24
Instead of a WebSocket.ErrorEvent
a custom error in the format of { T: 'error', code: 406, msg: 'connection limit exceeded' }
is returned. I made a PR for it: https://github.com/alpacahq/alpaca-ts/pull/118