-
Notifications
You must be signed in to change notification settings - Fork 12.8k
ES6 typings #987
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
ES6 typings #987
Conversation
* Allows manipulation and formatting of text strings and determination and location of substrings within strings. | ||
*/ | ||
declare var String: { | ||
interface StringConstructor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we set on _Constructor
? I have reservations because it's more than just a constructor; you have
fromCharCode(...codes: number[]): string;
which is a method on the static side. A lot of .d.ts
libraries tend to use the _Static
as a naming convention for these types.
I can honestly view it either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong feelings about the name. Personally I would rather not introduce a new named type and kept it the way it is now; and maybe we should.
But if we were to change it, am ok with type_static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer StringConstructor
. The ES spec calls it "the String Constructor" when describing the object and does not ever use the word "static" except to reserve it as a keyword.
@@ -193,7 +193,7 @@ module ts { | |||
|
|||
return { | |||
getSourceFile: getSourceFile, | |||
getDefaultLibFilename: () => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), "lib.d.ts"), | |||
getDefaultLibFilename: (options) => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no parens.
Conflicts: tests/baselines/reference/arrayTypeOfTypeOf.errors.txt tests/baselines/reference/redefineArray.errors.txt
* String.raw is intended for use as a tag function of a Tagged Template String. When called as such the first argument will be a well formed | ||
* template call site object and the rest parameter will contain the substitution values | ||
*/ | ||
raw(callSite: { raw: string; }, ...substitutions: any[]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callSite
is a misleading name; also, this doesn't have a return type annotation. It should be string[]
.
Are we going to include Side note: We've been having issues with how to deal with that when we try to typecheck a tagged template in ES5 mode, but when |
I think this a fair addition to the existing lib.d.ts, nothing dependent on the runtime here. So I would say just add the definition and I will be it up when I merge. |
you mean es6.d.ts? Took a look, looks good to me. Only minor concern is the duplication of methods on each TypedArray when it's very unlikely the different TA's will have different methods on them. |
Thanks @bterlson, I originally had one interface TypesArray that others inherited from bu did not want to add the extra name in the global namespace. i can go back there, should be less definitions overall. |
|
@@ -1171,6 +1171,7 @@ module ts { | |||
version?: boolean; | |||
watch?: boolean; | |||
preserveConstEnums?: boolean; | |||
allowNonTsExtensions?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens on compile on save - So what happens with emit - what file name do we give.. Should it be emitted? Should it be considered ts file and not .d.ts file? What about declaration file generation - I think we should give error if emit is called with this option. (Emit time error)
We need tests with and without this option and .d.ts and .js file generation. Can be compiler baseline I guess.
Conflicts: src/compiler/parser.ts src/compiler/tsc.ts src/harness/harness.ts src/harness/projectsRunner.ts tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt
Notes on @rbuckton 's remarks:
|
Regarding Promise Constructor, you are correct. It looks like the behavior of |
Conflicts: tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types
This is the first stab at ES6 typing's. i think i have all the main ones covered in this review.
There are still a main issue here that we are not handling, which is the manageability of the library. currently we have multiple files, for DOM webworkers, etc.. and the target adds another dimension.
We have talked about this before in the design meeting to add a new attribute that allows us to filter out types based on tags. this is a different issue and will be handled in a future change.
Still missing: