Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update target to es2024, use tsconfigs for typechecks, and run type checks at the top level (breaking changes) #2653

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

bdemann
Copy link
Member

@bdemann bdemann commented Feb 5, 2025

Contributor

  • Code has been declaratized
  • All new functions have JSDoc/Rustdoc comments
  • Error handling beautiful (no unwraps or expects etc)
  • Code tested thoroughly
    • it is troubling that this wasn't caught by the tests. That needs to be fixed
  • PR title:
    • Sentence cased
    • Described well for release notes
    • Indicates breaking changes with suffix "(breaking changes)"
  • Related issues have been linked and all tasks have been completed or made into separate issues
  • New documentation enumerated in the release issue
  • All breaking changes
    • Described below in the "Breaking Changes" section
    • Migration path described
  • Review is requested when ready

Reviewer

  • Code has been declaratized
  • All new functions have JSDoc/Rustdoc comments
  • Error handling beautiful (no unwraps or expects etc)
  • Code tested thoroughly
  • PR title:
    • Sentence cased
    • Described well for release notes
    • Indicates breaking changes with suffix "(breaking changes)"
  • Related issues have been linked and all tasks have been completed or made into separate issues
  • New documentation enumerated in the release issue
  • All breaking changes
    • Described below in the "Breaking Changes" section
    • Migration path described

Breaking Changes

  • Uint8Array must use explicit <ArrayBuffer> type argument instead of the default <ArrayBufferLike> type argument

@bdemann bdemann linked an issue Feb 7, 2025 that may be closed by this pull request
10 tasks
@bdemann bdemann changed the title restore module and update to ES2022 Update target to es2024, use tsconfigs for typechecks, and run type checks at the top level (breaking changes) Feb 8, 2025
@bdemann bdemann requested a review from lastmjs February 8, 2025 00:10
@lastmjs lastmjs enabled auto-merge February 8, 2025 00:31
@@ -126,7 +126,7 @@ async function prepareRequestBody(
init.body instanceof Float32Array ||
init.body instanceof Float64Array
) {
return new Uint8Array(init.body);
return new Uint8Array(init.body as ArrayBuffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk about this, if you just get rid of BigUint64Array and BigInt64Array in the union the error gets fixed. We should consider just doing that, and maybe this is some bug we should open an issue for somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should still file that issues somewhere?


- run: npm run typecheck
- run: npm run lint

check-test-success:
name: Check Azle tests succeeded
needs: run-tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we want top-level-checks to be hooked up here don't we? We need to make sure there's only pass or fail if run-tests and top-level-checks pass or fail...right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, done

@@ -202,7 +202,7 @@ async function prepareRequestBody(

if (typeof init.body === 'string') {
const textEncoder = new TextEncoder();
return [textEncoder.encode(init.body)];
return [textEncoder.encode(init.body) as Uint8Array<ArrayBuffer>];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss these casts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes let's

@@ -61,7 +61,7 @@ export async function fetchIcp(
}
);

const decodedResult = IDL.decode(funcIdl.retTypes, result);
const decodedResult = IDL.decode(funcIdl.retTypes, result.buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want to understand this. Let's discuss why this worked before, because it doesn't make sense to me fully why it would not continue to work.

@@ -21,8 +21,10 @@ export function isController(principal: Principal): boolean {
}

if (globalThis._azleIcExperimental !== undefined) {
const principalBytes =
principal.toUint8Array() as Uint8Array<ArrayBuffer>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa let's discuss this, I think there's a better way than these casts, I hope

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay let's discuss it

@@ -2,6 +2,7 @@
"compilerOptions": {
"strict": true,
"target": "ES2024",
"module": "ES2022",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module and moduleResolution are being taken care of in another PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ES022 now?

Copy link
Member Author

@bdemann bdemann Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ES2022 is what we agreed on for module... I thought.

Yes module and module resolution are in a separate issue. Though es2022 is the one I am planning on using for that pr.

@@ -0,0 +1,8 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help me to understand this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the package.json comment this is so that we can exclude all of the examples from the type checks. As long as we have to make a separate config for that I figured it would be good to add the other type checking settings like skipLibCheck and noEmit. We extend from the base tsconfig to make sure we use the same settings

@@ -3,7 +3,7 @@
"version": "0.25.0",
"description": "TypeScript and JavaScript CDK for the Internet Computer",
"scripts": {
"typecheck": "tsc --noEmit",
"typecheck": "tsc --project tsconfig.typecheck.json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help me to understand this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to type check the examples at this point. I was figuring that we didn't want to exclude the examples in the main tsconfig.json because it already had an exclude property that was only excluding the new examples (which actually needs to be updated? or gotten rid of, because it's in a new location. (just let me know which one that is and I will do it, otherwise I will add it to the issue about making the ideal tsconfig (another option is that we actually do just exclude the examples in the main ts config? I'm not sure how that would play off extending the main one though...))). Unfortunately you cannot, to my knowledge, pass an ignore list as a parameter, only in the tsconfig.json. You can make another tsconfig and point it tsc to it as a separate project. This allows us to have one tsconfig for building and one for typechecking.

test/index.ts Outdated
@@ -2,9 +2,14 @@ import * as dns from 'node:dns';
dns.setDefaultResultOrder('ipv4first');

import { describe, expect, test } from '@jest/globals';
import { execSync } from 'child_process';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using execSync?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have my reasons, but let's not worry about that, I'll just switch it to execSyncPretty

@@ -36,12 +41,11 @@ export function runTests(

if (shouldRunTypeChecks === true) {
describe(`type checks`, () => {
it('checks types', () => {
it('checks types', async () => {
const typeCheckCommand = `npm exec --offline tsc -- --noEmit --skipLibCheck`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we try to explicitly pass in the tsconfig.json of the project? Just like we do at the top level?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, I felt like passing in at the top level was a work around we had to do because of the extra files we wanted to ignore. I think this is a much better method under normal circumstances

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement top level azle checks
2 participants