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

Want to undefine some built-in functions #13508

Closed
gdh1995 opened this issue Jan 16, 2017 · 4 comments
Closed

Want to undefine some built-in functions #13508

gdh1995 opened this issue Jan 16, 2017 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@gdh1995
Copy link
Contributor

gdh1995 commented Jan 16, 2017

I want a keyword undeclare on declared interface/class methods and var which works where it's referenced. It will benefit developers who wants stricter constraints.

Syntactic

It should be like these:

undeclare var Symbol; // never needs Symbol

// a chrome extension restricted by CSP will wants setTimeout only to accept valid functions
undeclare function setTimeout(handler: any, timeout?: any, ...args: any[]): number;
// accept extra args which is not declared in `lib.dom.d.ts`
declare function setTimeout(handler: (...args: any[]) => void, timeout: number, ...args: any[]): number;

And the declaration after undeclare should be strictly matched:

  • if a var/class/namespace/interface is undeclare-ed, then only remove one record with the given type
  • if a (member) function is undeclared, types of args and its returned value should be strictly matched.

Motivation

Many EcmaScript functions are generic for backward compatibility and usability, but developers may have their own programming standard, and only want limited usages. For example:

  • a CSP of script-src: 'self' limits setTimeout and refuses eval.
  • some APIs are deprecated and replaced by new ones.
  • a Chrome extension knows that it will has a complete chrome.tabs.Tab and tab.title is not string | undefined but string.

In my tests, I'm able to override definitions of member variables, so there has been a work-around for cases like tab.title (edit: it reported "All declarations of 'title' must have identical modifiers"), but I can not find any way to remove function definitions.

@aluanhaddad
Copy link
Contributor

This is related to #4183

@mhegazy
Copy link
Contributor

mhegazy commented Jan 16, 2017

Global declarations are all originating from declaration files. The library file (lib.*.d.ts) are overridable. use --noLib and specify your declaration file that does not define Symbol, setTimeout or any other APIs deemed unsafe, and pass that to the compiler instead.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 16, 2017
@gdh1995
Copy link
Contributor Author

gdh1995 commented Jan 16, 2017

The ability is important for me to remove built-in function declarations, which is a little different from #4183.

I need to operate with many DOM APIs so lib.dom.d.ts is needed, but setTimeout is there, too. Must I copy the whole lib.dom.d.ts and then modify just few lines?

@mhegazy
Copy link
Contributor

mhegazy commented Jan 16, 2017

if you want to change the built in APIs, you can. You can start with removing two, or more, up to you.

@gdh1995 gdh1995 closed this as completed Jan 31, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants