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

Remove hand crafted types for text-encoding #6

Merged
merged 1 commit into from
Jun 1, 2018

Conversation

mohsen1
Copy link
Contributor

@mohsen1 mohsen1 commented May 29, 2018

Still WIP but comments are welcome

This change:

  • Removes hand written types for text-encoding module and uses @types/text-encoding
  • Updates the list script to enforce TypeScript type checking and Prettier code lint (must ran Prettier before)

TODO List:

  • Resolve all tsc issues
    • Fix duplicate declaration for global TextDecoder and TextEncoder. It already exist in dom.d.ts
    • Figure out typing for *.pb (protobuf?) files. I need help with this. Should we have a declaration per file? Can we use something like Proto2TypeScript to automate it?

.gitignore Outdated
@@ -6,3 +6,4 @@ assets.go
msg.pb.go
msg.pb.js
msg.pb.d.ts
.vscode

Choose a reason for hiding this comment

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

FYI, you can ignore this file globally so you don't have to add it to each repo individually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's nice and I did it on my machine. I think it's good to have it here too since VSCode is pretty popular these days :)

Choose a reason for hiding this comment

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

I find it it best to keep the files in each repository specific to that project instead of about the people editing it. This project has no reliance on or interactions with VS Code. But it all comes down to personal preference in the end.

@@ -0,0 +1,14 @@
declare module "*.pb" {
Copy link
Contributor

Choose a reason for hiding this comment

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

protobuf auto-generates this file based on contents inside msg.proto, look at msg.pb.d.ts after running:

make deno

or in case you don't want to build v8 (which takes ~30min)

make msg.pb.d.ts

@ry
Copy link
Member

ry commented May 29, 2018

@mohsen1 thanks! I applaud the effort. If you can remove text-encoding.d.ts while also not depending on @types/text-encoding, I would be very happy. I tried a bit to do this but got stuck.

@CLAassistant
Copy link

CLAassistant commented May 30, 2018

CLA assistant check
All committers have signed the CLA.

@mohsen1 mohsen1 changed the title [WIP] Remove hand crafted types Remove hand crafted types for text-encoding May 30, 2018
@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 1, 2018

@ry you can't import from "text-encoding" module without having it declared somewhere.

https://github.com/ry/deno/blob/a4d89f2ee1ddde786f2335eada86f00e3efd1174/globals.ts#L54

This is the minimal declaration if you don't like to have a dependency just for types.

tsconfig.json Outdated
@@ -1,14 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why removing this option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shoot! I didn't meant to dod that!

runtime.ts Outdated
@@ -149,7 +149,7 @@ export function resolveModule(
let fetchResponse;
try {
fetchResponse = os.codeFetch(moduleSpecifier, containingFile);
} catch(e) {
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change might be fixed at #73 :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change

Copy link
Contributor

@qti3e qti3e left a comment

Choose a reason for hiding this comment

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

Thank you Moshen, it looks good to me, I have a few comments...
Also, please squash : )

.gitignore Outdated
@@ -6,3 +6,4 @@ assets.go
msg.pb.go
msg.pb.js
msg.pb.d.ts
.vscode
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change

package.json Outdated
"lint": "tslint -p tsconfig.json -c tslint.json",
"fmt": "prettier --write *.ts* *.js *.json"
"lint": "tslint -p . && prettier --list-different \"{*.ts,js,json}\"",
"fmt": "prettier --write \"{*.ts,js,json}\""
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change

runtime.ts Outdated
@@ -149,7 +149,7 @@ export function resolveModule(
let fetchResponse;
try {
fetchResponse = os.codeFetch(moduleSpecifier, containingFile);
} catch(e) {
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change

@mohsen1 mohsen1 force-pushed the remove-hand-crafted-types branch 2 times, most recently from cdc3f8c to e5f09fe Compare June 1, 2018 16:21
@mohsen1 mohsen1 force-pushed the remove-hand-crafted-types branch from e5f09fe to e54ba89 Compare June 1, 2018 16:22
@ry
Copy link
Member

ry commented Jun 1, 2018

This doesn't solve the TODO. Thanks for researching it. We can revisit later with that TS issue is fixed.

@ry ry closed this Jun 1, 2018
@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 1, 2018

I don't understand how it would be possible to import from text-encoding module if you don't want to depend on@types/text-encoding and delete text-encoding.d.ts. Module has to be declared somehow

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 1, 2018

A module with "text-encoding" specifier is not defined in lib.dom.d.ts. If I'm reading the code correctly you are importing a runtime value from the text encoding module and assigning it to global object.

@ry
Copy link
Member

ry commented Jun 1, 2018

Right.. so somehow we need to import the implementation (polyfill) but not have typescript complain about types missing.

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 1, 2018

To import those values from "text-encoding" module there should be a module declaration somewhere. There are two options :

  1. create a minimal module declaration that declares exports of TextEncoder and TextDecoder with types of dom lib. That would be this PR. TypeScript has two variable namespaces. One for values and one for types. That's why I have TextDecoder: TextDecoder

  2. depend on @types/text-encoder which declares the module. I'm trying to fix it to use dom types here use native DOM types for text-encoding module DefinitelyTyped/DefinitelyTyped#26141

@ry
Copy link
Member

ry commented Jun 1, 2018

@mohsen1 oh gosh I'm very sorry. I miss read the commit - I thought it was still importing @types/text-encoder.
Thank you for solving this! (And thank you @yorkie and @qti3e for reviewing)

@ry ry reopened this Jun 1, 2018
@ry ry merged commit 7b5fbc7 into denoland:master Jun 1, 2018
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.

None yet

6 participants