-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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
isundeclare
-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'
limitssetTimeout
and refuseseval
. - some APIs are
deprecated
and replaced by new ones. - a Chrome extension knows that it will has a complete
chrome.tabs.Tab
andtab.title
is notstring | undefined
butstring
.
In my tests, I'm able to override definitions of member variables, so there has been a work-around for cases like (edit: it reported "All declarations of 'title' must have identical modifiers"), but I can not find any way to remove tab.title
function
definitions.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug