Clarification
This is answered by upon the federal income tax in the United States. State and local income taxes and income taxes in other countries don't usually define key terms like income in exactly the same way, although many of the distinctions are irrelevant for the purpose of the specific example presented.
Short Answer
I have performed a service for someone. They offer to pay me for that
service. I say "hey, instead, give that money to so-and-so charity".
They say "okay".
In all likelihood, in the facts of the question, you do not have income until you are actually paid because you are almost surely a cash basis tax accounting taxpayer. So, you have no income and no charitable deduction in this example.
But, if you are an accrual basis tax accounting taxpayer, you have income when it is earned even if you haven't been paid yet. If you were, you would have income in this example, because you already earned it, and then would be entitled to a charitable deduction unless limitations on the charitable deduction (e.g. the requirement that you itemize your deductions rather than taking the standard deduction) prevents you from doing so.
Long Answer
The technical answer to the larger question is that income is defined in 26 U.S.C. § 61 and in 26 C.F.R. § 1.61-1 to 26 CFR § 1.61-22 and related revenue rulings and case law. But, as 26 C.F.R. § 1.61-1 explains, after providing a general definition, there are lots of other sections of the tax code that provide additional clarification regarding what constitutes income.
§ 1.61-1 Gross income.
(a) General definition. Gross income means all income from whatever
source derived, unless excluded by law. Gross income includes income
realized in any form, whether in money, property, or services. Income
may be realized, therefore, in the form of services, meals,
accommodations, stock, or other property, as well as in cash. Section
61 lists the more common items of gross income for purposes of
illustration. For purposes of further illustration, § 1.61-14 mentions
several miscellaneous items of gross income not listed specifically in
section 61. Gross income, however, is not limited to the items so
enumerated.
(b) Cross references. Cross references to other provisions of the
Code are to be found throughout the regulations under section 61. The
purpose of these cross references is to direct attention to the more
common items which are included in or excluded from gross income
entirely, or treated in some special manner. To the extent that
another section of the Code or of the regulations thereunder, provides
specific treatment for any item of income, such other provision shall
apply notwithstanding section 61 and the regulations thereunder. The
cross references do not cover all possible items.
(1) For examples of items specifically included in gross income, see
Part II (section 71 and following), Subchapter B, Chapter 1 of the
Code.
(2) For examples of items specifically excluded from gross income, see
part III (section 101 and following), Subchapter B, Chapter 1 of the
Code.
(3) For general rules as to the taxable year for which an item is to
be included in gross income, see section 451 and the regulations
thereunder.
Also, while it isn't evident on the face of this tax code section and the relevant regulations, the definition of income is not the same for all taxpayers.
In particular, I've highlighted the key word in the definition for the purposes of this question which is "realized" which means one thing for cash based tax accounting taxpayers and another for accrual based tax accounting taxpayers.
This distinction is buried in much more obscure part of the Internal Revenue Code and Treasury Regulations and isn't actually found in any of the sections referenced above. Some aspects of this distinction aren't found in the tax code or regulations at all, and instead, incorporates by reference accounting concepts from outside of tax law that aren't affirmative spelled out in detail entirely within in any enacted tax legislation or Treasury regulations.
Probably the most convenient IRS resource explaining this distinction is IRS Publication 538, which (like all official IRS publications) has the force of a Treasury regulation as legal authority, even though it isn't part of the Internal Revenue Code, and isn't part of the Code of Federal Regulations, and doesn't have the same format as a usual Treasury Regulation.
Most taxpayers are cash basis taxpayers, and if you use that accounting system, you "realize" income only when you actually receive payment.
On the other hand, most C-corporations (especially publicly held companies), and some other taxpayers, are either required to, or elect to, use a different accounting system, called "accrual accounting", in which a taxpayer "realize" income when it is earned, even if this happens before the taxpayer actually receives payment (it means other things too, that are not relevant to the question).
In the example of the question, if you are a cash basis taxpayer, you do not have income under Section 61 of the Internal Revenue Code (which is Title 26 of the United States Code) because as a cash based accounting system taxpayer you only realize income when you are paid. Since you were not actually paid before you forfeited your legal right to be paid so that the charity could have it, you didn't have income in this transaction. And, since you never had that income for tax purposes, you cannot deduct the benefit you provide to a charity that could have been income to you if you declined to make the contribution, as a charitable deduction.
In contrast, if you were an accrual basis taxpayer (which, in all likelihood, you are not), you realize income when you have earned it, and since you had a legal right to be paid, you would have realized the income from you work, and then would have made a charitable deduction in the amount that you were entitled to be paid. But the availability of the charitable deduction would be subject to limitations on the charitable deduction that don't apply to merely unrealized potential to have income.
For example, individual taxpayers who don't itemize their deductions aren't entitled to claim the charitable deduction in most cases, and even other taxpayers are subject to sometimes complicated limitations on how much of a charitable tax deduction they are allowed to claim.